cURL / Mailing Lists / curl-library / Single Mail

curl-library

Re: Uploading file to auth http server, when login url is different to upload url??

From: Dan Fandrich <dan_at_coneharvesters.com>
Date: Wed, 1 Nov 2006 10:25:57 -0800

On Wed, Nov 01, 2006 at 05:32:21PM +0000, Theodore H. Smith wrote:
> I want to log into into a certain url with http auth by supplying a
> name and password, and without breaking the http connection, then
> upload a file to a different url!

"without breaking the http connection" implies that HTTP is a stateful
protocol, which it is not. This means that the server shouldn't care
if you perform two requests on a single TCP connection or two. If you
have a case where you need to "log in" to one URL, then perform an
operation on another URL, usually the state is held in cookies. Have
you tried to skip the "log in" URL and simply do the upload on the
second URL, but providing the proper authentication IDs? That should
work unless cookies are being used.

> It's done on the PC using this library called W3Client which was
> found on codeproject.com:
>
> W3Client w3;
>
> w3.Connect("http://gdst2.simslearning.co.uk/learnwise", username,
> password); // logs in here
>
> w3.AddPostArgument("course", strFile, TRUE);
>
> w3.Request("/coursebuilder/importCourse/org/dep",
> W3Client::reqPostMultipartsFormdata); // uploads!
>
>
> See, easy!

The simple libcurl equivalent isn't *that* much worse; see
docs/examples/simple.c for a simple download program, for example.

> I tried with curl (as a shell tool not library), which eventually I
> found couldn't work, simply because... I can't log into one url and
> then upload to another. I tried all sorts of different combinations

Sure you can. If the state is stored in cookies, then just give two
curl commands, the first login one with the -c option, the second upload
one with the -b option.

> with curl. I tried multiple connection attempts (calling curl then
> calling it again after it completes). I tried passing two urls to
> curl, that also failed because the login page refuses to login if
> I've got any POST arguments!
>
> It just won't work.
>
> Can Macs even do this?

It's not a Mac-specific issue.

> Must I resort to writing my own socket wrapper and do all the http
> stuff manually? :( If it can't be done with curl, perhaps some Mac
> people can tell me the easiest way to do this? As it looks to me,
> Cocoa can't do it.

It probably can, once you figure out what's involved in "logging in".

>>> Dan

-- 
http://www.MoveAnnouncer.com              The web change of address service
          Let webmasters know that your web site has moved
Received on 2006-11-01