cURL / Mailing Lists / curl-library / Single Mail

curl-library

Re: https redirect problem?

From: Iris Jing <iris_jing_at_msn.com>
Date: Tue, 12 Oct 2004 23:07:54 -0400

Hi Daniel,

Thanks for your quick response.

A few things to clarify --

What you understand is correct. I got the page I want with curl (even the old version) but not when using libcurl from my
program. I actually didn't find any bug in the old version of curl (7.10.6) for this small task and didn't
use -L, but still it worked. Thanks for clarifying the redirect concept for me. I said that the libcurl doesn't seem to support *redirect*
because I sent exactly the same request in my program as curl, i.e.

For curl, I used:

$curl https://username:password@my.xxxxx.net:443/NOTlogindir/MyTargetFile.jsp

I got the file I want.

However, when I send request from my program like this:

..curl_easy_setopt(curl, CURLOPT_URL, "https://username:password@my.xxxxx.net:443/NOTlogindir/MyTargetFile.jsp");

I only obtained the login page (login.jsp). Note that the above two https URLs are exactly the same. So it seems to me that curl got passed
the authentication and grab the file properly (*redirect* to MyTargetFile after login); while libcurl couldn't do that, it only passed the authentication and then grab the login-in page!

I've turned the VERBOSE option on, otherwise, i won't be able to get detailed info. from my program. I got the following verbose info (in P.S.) and tried to compare the difference of the verbose info. for curl and my own program (which uses libcurl). It seems to be something with the header and cookies. Note that the Curl verbose has "User Agent" info while the libcurl doesn't. Do I have to handle the user-agent in the program for
https web? For cookies, I tried to turn on the COOKIEJAR, but still didn't work out. The cookies for Curl and libcurl are different because they're actually from different pages: Curl grabs cookies from MyTargetFile.jsp, while libcurl got it from login.jsp, that's what I assumed. From what you suggested in the last message:

" curl uses libcurl so yes, libcurl does everything transfer-related that curl does. "

I suspect that I either haven't got the right version of libcurl (I'm using curlpp0.3.1 now), or there could be something wrong with my program, but
still couldn't figure out what it is. Should I use this one -- curl-7.12.1.tar.gz at http://curl.haxx.se/download.html? Or you think it doesn't matter
that I use curlpp0.3.1 or curl-7.12.1. Thanks.
 
Best regards,
Iris

P.S.============ my program (libcurl) verbose ==============
Authorization: Basic XXXXXXXXXXXXXXXXXXXX==

Host: my.xxxxx.net

Pragma: no-cache

Accept: image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, */*

HTTP/1.1 200 OK

Date: Thu, 07 Oct 2004 20:04:52 GMT

Server: HP Apache-based Web Server/1.3.26 (Unix) mod_ssl/2.8.9 OpenSSL/0.9.6c

Set-Cookie: JSESSIONID=XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX; path=/

Transfer-Encoding: chunked

Content-Type: text/html

==============================

============ Curl verbose ========
Authorization: Basic XXXXXXXXXXXXXXXXXXX==

User-Agent: curl/7.10.6 (i386-redhat-linux-gnu) libcurl/7.10.6 OpenSSL/0.9.7a ipv6 zlib/1.1.4

Host: my.xxxxx.net

Pragma: no-cache

Accept: image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, */*

HTTP/1.1 200 OK

Date: Wed, 06 Oct 2004 00:31:43 GMT

Server: HP Apache-based Web Server/1.3.26 (Unix) mod_ssl/2.8.9 OpenSSL/0.9.6c

Set-Cookie: CTSESSION=XXXXXXXXXXXXXX; domain=.xxxxx.net; path=/

Set-Cookie: BIGipServersslmbea_xxxxx_http=XXXXXXXXX.XXXXX.0000; path=/

Set-Cookie: JSESSIONID=XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX; path=/

Cache-control: no-cache="set-cookie"

Transfer-Encoding: chunked

Content-Type: text/html

=============================================

....................................

On Sun, 10 Oct 2004, Iris Jing wrote:

..

> it doesn't seem to handle https redirect properly. (At first I tought it
> could be within curlpp wrapper, but then I figured out it shouldn't,

..

> As I have RedHat linux installed, so there is already a bundled curl
> (7.10.6), which is under /usr/bin.

This is a pretty old version so you don't surprise us if you find many bugs in
it.

> $curl password_at_my.xxxxx.net/XXX/XXX/XXX.jsp">https://username:password_at_myxxxxx.net/XXX/XXX/XXX.jsp
>
> and it worked perfectly! (I even don't need to put -L option in the command
> line. I got the file I want.

This is a clue for you: without -L it doesn't follow redirects. Your issue has
nothing to do with redirects and I don't know why you ever thought so.

> < HTTP/1.1 200 OK

No 3XX code and no Location: header = no redirect.

> I'm thinking that the problem could be within libcurl, because the curl
> seems to be able to handle https web rediction properly...

This is no redirection.

> I understand that curl and libcurl are totally different things, curl is a
> command-line tool. While if curl can handle https redirect w/o problem, I
> assume that libcurl should be able to do something similar.

curl uses libcurl so yes, libcurl does everything transfer-related that curl
does.

> I suppose if curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1) works, then
> after the authentication (which already happened properly), it should
> automatically redirect to the https webpage I intended to fetch (but it
> didn't)

If the server would respond with a proper 3XX code and a Location: header,
then yes, but otherwise no.

> Any suggestion would be greatly appreciated. Thanks in advance.

I'm having a hard time just to understand your question. As I understand it,
you get the page you want with curl but not when using libcurl from your
program?

Then I suggest you make your program send the exact same request as curl does.
Use CURLOPT_VERBOSE and curl -v to get the details.

-- 
Received on 2004-10-13