curl-library
Re: Object Moved/Location cut-off ?
Date: Mon, 24 Jun 2002 13:58:57 -0400
> > The first time I send my info to the side, they send back a cookie (and
> > since I performed the curl with the
> > curl_easy_setopt(plug_args->curl_handle, CURLOPT_COOKIEFILE,
> > "mycookies.fil"), I'm assuming that enables the cookie parser as explained
> > in the docs).
>
> Yes, it should do that.
>
> > They also send back an "Object Moved" header with the "Location:" of where
> > I need to send curl next.
>
> ... unless you tell curl to do it, then you won't have to do it yourself.
===============================================================================
How do I tell curl to follow the "Location:" redirect?
>
> > However, the "Location:" seems to be cut off, I only get the following in
> > the header:
> >
> > HTTP/1.1 302 Object Moved
> > Server: Microsoft-IIS/4.0
> > Date: Sat, 22 Jun 2002 01:56:42 GMT
> > Connection: close
> > Location: http://cgi3.ebay.com/aw-cgi/eBayISAPI.dll?
>
> This seems veeeery strange. Have you tried using a network analyzer or
> anything to see if this really is curl not reading the full header or if the
> header arrives broken?
=================================================================================
I tried using the command line version of curl, which seems to work fine.
I made a script that looks something like this:
#!/bin/bash
curl -c mycookiejar.fil \
-d MfcISAPICommand=AdultLogin \
-d userid=myaccount \ # <--- My actual E-bay account name (I deleted it in this mail)
-d password=%33%33%33 \ # <--- My URL encoded password (I deleted it in this mail)
-D myheaders.fil \
-G \
-L \
-o myoutput.fil \
--url http://cgi.ebay.com/aw-cgi/eBayISAPI.dll
Here's what I got as a result:
mycookiejar.fil >
# Netscape HTTP Cookie File
# http://www.netscape.com/newsref/std/cookie_spec.html
# This file was generated by libcurl! Edit at your own risk.
.ebay.com TRUE / FALSE 0 s AQAAAAEAAAASAAAARAAAAIBJFj0AhB89QDEyLjIyNy40LjYwZTF0ZXN0Q29va2llICQyJGN1cmwvNy45JEtpQjVLcUljbnBQdGJ4YS5KMTFwZS8Am
myheaders.fil >
HTTP/1.1 302 Object Moved
Server: Microsoft-IIS/4.0
Date: Sun, 23 Jun 2002 22:19:43 GMT
Connection: close
Location: http://cgi3.ebay.com/aw-cgi/eBayISAPI.dll?SignIn&UsingSSL=0&pUserId=&ru=http%3A%2F%2Fcgi3.ebay.com%2Faw-cgi%2FeBayISAPI.dll%3FAdultLoginShow%26pass%3D%7B_pass_%7D%26userid%3D&pp=pass&pageType=94&i1=0
HTTP/1.1 200 OK
Server: Microsoft-IIS/4.0
Date: Sun, 23 Jun 2002 22:19:43 GMT
Connection: close
HTTP/1.1 200 OK
Server: Microsoft-IIS/4.0
Date: Sun, 23 Jun 2002 22:19:44 GMT
Connection: close
Set-Cookie: s=AQAAAAEAAAASAAAARAAAAIBJFj0AhB89QDEyLjIyNy40LjYwZTF0ZXN0Q29va2llICQyJGN1cmwvNy45JEtpQjVLcUljbnBQdGJ4YS5KMTFwZS8Am; path=/; domain=.ebay.com
HTTP/1.1 200 OK
Server: Microsoft-IIS/4.0
Date: Sun, 23 Jun 2002 22:19:44 GMT
Connection: close
and the myoutput.fil just contained the HTML from the site.
>
> > HTTP/1.1 501 Not Implemented
>
> Does this follow the Location: header? In that case it looks even more weird.
=================================================================================
Yes, I pasted it exactly as it responded.
>
> > So where do I go from here?
>
> Well, if it is possible, I'd like to see an as small program source code as
> possible that can repeat this problem.
>
==================================================================================
OK, here's the main part of my program that does this:
void get_url()
{
extern struct plugin_struct *plug_args;
// If there is no URL then fail!
if(plug_args->url[0]=='\0') {
return_state(FALSE, plug_args);
return;
}
// If the HTML buffer is full, clear it out.
if(plug_args->html_buff!=(char *)NULL) {
memset(plug_args->html_buff,0,sizeof(*plug_args->html_buff));
free(plug_args->html_buff);
plug_args->html_buff = (char *)NULL;
plug_args->buff_size = 0;
}
// Get a curl handle.
plug_args->curl_handle = curl_easy_init();
// If there is POST data, use it, in GET mode.
if(plug_args->post_data[0]!='\0') {
curl_easy_setopt(plug_args->curl_handle, CURLOPT_POSTFIELDS, plug_args->post_data);
curl_easy_setopt(plug_args->curl_handle, CURLOPT_HTTPGET, TRUE);
}
// Set the curl options:
// Set the URL
curl_easy_setopt(plug_args->curl_handle, CURLOPT_URL, plug_args->url);
// Set the function to read the output from curl
curl_easy_setopt(plug_args->curl_handle, CURLOPT_WRITEFUNCTION, html2buff);
// Don't pass anything else to my function
curl_easy_setopt(plug_args->curl_handle, CURLOPT_FILE, (void *)NULL);
// Enable the cookie parser by pointing to a filename that doesn't exist
curl_easy_setopt(plug_args->curl_handle, CURLOPT_COOKIEFILE, "mycookies.fil");
// Debug stuff
#ifdef DEBUG
curl_easy_setopt(plug_args->curl_handle, CURLOPT_VERBOSE, TRUE);
curl_easy_setopt(plug_args->curl_handle, CURLOPT_HEADER, TRUE);
#endif
// Perform the curl function
curl_easy_perform(plug_args->curl_handle);
// Cleanup curl
curl_easy_cleanup(plug_args->curl_handle);
// Clear the handle
plug_args->curl_handle = (CURL *)NULL;
// Return success
return_state(TRUE, plug_args);
return;
}
> > I tried to make my own HTTP/HTML handling code, but it got too complicated.
> > I was hoping curl would help.
>
> curl is indeed capable or at least assumed to be capable of this.
>
> --
> Daniel Stenberg -- curl groks URLs -- http://curl.haxx.se/
-------------------------------------------------------
Sponsored by:
ThinkGeek at http://www.ThinkGeek.com/
Received on 2002-06-24