Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Changing Default Accept Type for WinHTTPOpenRequest

1,277 views
Skip to first unread message

Vanessa

unread,
Feb 4, 2003, 1:30:42 PM2/4/03
to
I'm trying to use WinHTTP to check to see if a file
exists on a URL. I'm using the WinHTTPOpenRequest
function to create an HTTP request handle like this:

if (m_hConnect)
hRequest = WinHttpOpenRequest(m_hConnect, L"GET",
objectName, NULL, WINHTTP_NO_REFERER,
WINHTTP_DEFAULT_ACCEPT_TYPES, m_openOptions);

where objectName = L"DataAvailable/filequeue.txt"

When I call the function as above, I can get a request
handle. However, that code assumes that I'm looking for
text-based files (e.g. accept type = text/plain). So, if
I query the URL for filequeue.txt, I know that I am
accessing the right file because the correct file size is
returned in this call:

if (WinHttpQueryDataAvailable(hRequest, &availableBytes))

However, when I try to modify my call to
WinHTTPOpenRequest to accept different media-types, I get
an error. I set my code up like so:

const wchar_t *att[] = { L"text/plain",
L"multipart/signed" };

if (m_hConnect)
hRequest = WinHttpOpenRequest(m_hConnect, L"GET",
objectName, NULL, WINHTTP_NO_REFERER, att, m_openOptions);

The hRequest var is not populated and GetLastError()
returns:

Error #87: The parameter is incorrect.

I need the request to look for signed message files and
compressed files (.p7b and .zip). When I try to use
WinHTTPOpenRequest with the default accept types and with
objectName = L"DataAvailable/message.p7b", I get a
request handle, but the call to WinHTTPQueryDataAvailable
returns 789 as the available bytes when the file size is
like 3200 bytes.

So it seems that my problem is that WinHTTPOpenRequest
will not accept different media-types.

I've searched msdn and the msdn newsgroups to no avail.
If you could provide any insight, I'd sincerely
appreciate it.

Stephen Sulzer [MSFT]

unread,
Feb 4, 2003, 4:16:26 PM2/4/03
to
Hello,

There is a minor defect in your code concerning the AcceptTypes array given
to WinHttpOpenRequest. Because there is no parameter to WinHttpOpenRequest
that specifies the number of elements in the AcceptTypes array, the API
expects a NULL element to indicate the end of the array. Therefore, your
AcceptTypes array should look like:


const wchar_t *att[] = { L"text/plain", L"multipart/signed", NULL }; //
array must have NULL terminator


Hope that helps.


Regards,

Stephen Sulzer
Microsoft Corporation

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

"Vanessa" <vanessa...@hotmail.com> wrote in message
news:06d001c2cc7b$85fc8dc0$8af82ecf@TK2MSFTNGXA03...

0 new messages