Discussion:
Get the Required Resource File Name Failed
(too old to reply)
shicheng
2008-10-13 07:48:00 UTC
Permalink
Hi,
I want to get the field "Location" from the HTTP header using
WinHttpQueryHeaders, but it fails with error code
ERROR_WINHTTP_HEADER_NOT_FOUND. I don’t know why because the field
"Location" exists in the header which can be seen by a network monitoring
tool. I want to get this field because I want to get the file name of the
required resource just as IE does.
This is the code I used:
WinHttpQueryHeaders(hRequest,
WINHTTP_QUERY_LOCATION,
WINHTTP_HEADER_NAME_BY_INDEX,
NULL,
&dwSize,
WINHTTP_NO_HEADER_INDEX);

I print the all the header and find the field “Location” is not there.
This is the code I used:
WinHttpQueryHeaders(hRequest,
WINHTTP_QUERY_RAW_HEADERS_CRLF,
WINHTTP_HEADER_NAME_BY_INDEX,
NULL,
&dwSize,
WINHTTP_NO_HEADER_INDEX);
Can anyone tell me how to get the required resource name please? Thank you!
Eric Loewenthal
2008-11-11 06:16:00 UTC
Permalink
Hi,

Per the HTTP 1.1 RFC:
14.30 Location
The Location response-header field is used to redirect the recipient to a
location other than the Request-URI for completion of the request or
identification of a new resource. For 201 (Created) responses, the Location
is that of the new resource which was created by the request. For 3xx
responses, the location SHOULD indicate the server's preferred URI for
automatic redirection to the resource. The field value consists of a single
absolute URI.
Location = "Location" ":" absoluteURI

Likely WinHTTP is doing this on behalf of the caller. Looking at Netmon can
you tell me what the status code is and do you see a susequent request to the
URL with in the "Location" header on the original request?

If you first call WinHttpSetOption with
WINHTTP_OPTION_DISABLE_FEATURE/WINHTTP_DISABLE_REDIRECTS
on the request handle you should be able to query the header. Once disabled,
WinHttp will return you the 302 headers and entity body, and a subsequent
WinHttpSendRequest using the same handle will send the request to the new
destination.

WINHTTP_DISABLE_REDIRECTS
Automatic redirection is disabled when sending requests with
WinHttpSendRequest. If automatic redirection is disabled, an application must
register a callback function in order for Passport authentication to succeed.

This posting is provided "AS IS" with no warranties, and confers no rights.

Eric Loewenthal
Post by shicheng
Hi,
I want to get the field "Location" from the HTTP header using
WinHttpQueryHeaders, but it fails with error code
ERROR_WINHTTP_HEADER_NOT_FOUND. I don’t know why because the field
"Location" exists in the header which can be seen by a network monitoring
tool. I want to get this field because I want to get the file name of the
required resource just as IE does.
WinHttpQueryHeaders(hRequest,
WINHTTP_QUERY_LOCATION,
WINHTTP_HEADER_NAME_BY_INDEX,
NULL,
&dwSize,
WINHTTP_NO_HEADER_INDEX);
I print the all the header and find the field “Location” is not there.
WinHttpQueryHeaders(hRequest,
WINHTTP_QUERY_RAW_HEADERS_CRLF,
WINHTTP_HEADER_NAME_BY_INDEX,
NULL,
&dwSize,
WINHTTP_NO_HEADER_INDEX);
Can anyone tell me how to get the required resource name please? Thank you!
shicheng
2008-11-11 06:53:01 UTC
Permalink
Yes, Eric. I have figured it out by monitoring the http requests and
responses with a network traffic tool. It is just like you said, WinHttp
APIs handle the redirecting of the server by default, so we won't get the
response headers or contents in after the redirect. After I disable the
redirecting, I get everything I want.

It is the same reason of another thread posted by me which talks about
missing cookies in the response header.

Thank you very much.
Post by Eric Loewenthal
Hi,
14.30 Location
The Location response-header field is used to redirect the recipient to a
location other than the Request-URI for completion of the request or
identification of a new resource. For 201 (Created) responses, the Location
is that of the new resource which was created by the request. For 3xx
responses, the location SHOULD indicate the server's preferred URI for
automatic redirection to the resource. The field value consists of a single
absolute URI.
Location = "Location" ":" absoluteURI
Likely WinHTTP is doing this on behalf of the caller. Looking at Netmon can
you tell me what the status code is and do you see a susequent request to the
URL with in the "Location" header on the original request?
If you first call WinHttpSetOption with
WINHTTP_OPTION_DISABLE_FEATURE/WINHTTP_DISABLE_REDIRECTS
on the request handle you should be able to query the header. Once disabled,
WinHttp will return you the 302 headers and entity body, and a subsequent
WinHttpSendRequest using the same handle will send the request to the new
destination.
WINHTTP_DISABLE_REDIRECTS
Automatic redirection is disabled when sending requests with
WinHttpSendRequest. If automatic redirection is disabled, an application must
register a callback function in order for Passport authentication to succeed.
This posting is provided "AS IS" with no warranties, and confers no rights.
Eric Loewenthal
Post by shicheng
Hi,
I want to get the field "Location" from the HTTP header using
WinHttpQueryHeaders, but it fails with error code
ERROR_WINHTTP_HEADER_NOT_FOUND. I don’t know why because the field
"Location" exists in the header which can be seen by a network monitoring
tool. I want to get this field because I want to get the file name of the
required resource just as IE does.
WinHttpQueryHeaders(hRequest,
WINHTTP_QUERY_LOCATION,
WINHTTP_HEADER_NAME_BY_INDEX,
NULL,
&dwSize,
WINHTTP_NO_HEADER_INDEX);
I print the all the header and find the field “Location” is not there.
WinHttpQueryHeaders(hRequest,
WINHTTP_QUERY_RAW_HEADERS_CRLF,
WINHTTP_HEADER_NAME_BY_INDEX,
NULL,
&dwSize,
WINHTTP_NO_HEADER_INDEX);
Can anyone tell me how to get the required resource name please? Thank you!
Loading...