5 out of 22 rated this helpful Rate this topic

HttpOpenRequest function

Creates an HTTP request handle.

Syntax

HINTERNET HttpOpenRequest(
  __in  HINTERNET hConnect,
  __in  LPCTSTR lpszVerb,
  __in  LPCTSTR lpszObjectName,
  __in  LPCTSTR lpszVersion,
  __in  LPCTSTR lpszReferer,
  __in  LPCTSTR *lplpszAcceptTypes,
  __in  DWORD dwFlags,
  __in  DWORD_PTR dwContext
);

Parameters

hConnect [in]

A handle to an HTTP session returned by InternetConnect.

lpszVerb [in]

A pointer to a null-terminated string that contains the HTTP verb to use in the request. If this parameter is NULL, the function uses GET as the HTTP verb.

lpszObjectName [in]

A pointer to a null-terminated string that contains the name of the target object of the specified HTTP verb. This is generally a file name, an executable module, or a search specifier.

lpszVersion [in]

A pointer to a null-terminated string that contains the HTTP version. If this parameter is NULL, the function uses HTTP/1.1 as the version.

lpszReferer [in]

A pointer to a null-terminated string that specifies the URL of the document from which the URL in the request (lpszObjectName) was obtained. If this parameter is NULL, no referrer is specified.

lplpszAcceptTypes [in]

A pointer to a null-terminated array of strings that indicates media types accepted by the client. If this parameter is NULL, no types are accepted by the client. Servers generally interpret a lack of accept types to indicate that the client accepts only documents of type "text/*" (that is, only text documents—no pictures or other binary files). For more information and a list of valid media types, see ftp://ftp.isi.edu/in-notes/iana/assignments/media-types/media-types.

dwFlags [in]

Internet options. This parameter can be any of the following values.

ValueMeaning
INTERNET_FLAG_CACHE_IF_NET_FAIL

Returns the resource from the cache if the network request for the resource fails due to an ERROR_INTERNET_CONNECTION_RESET (the connection with the server has been reset) or ERROR_INTERNET_CANNOT_CONNECT (the attempt to connect to the server failed).

INTERNET_FLAG_HYPERLINK

Forces a reload if there was no Expires time and no LastModified time returned from the server when determining whether to reload the item from the network.

INTERNET_FLAG_IGNORE_CERT_CN_INVALID

Disables checking of SSL/PCT-based certificates that are returned from the server against the host name given in the request. WinINet functions use a simple check against certificates by comparing for matching host names and simple wildcarding rules.

INTERNET_FLAG_IGNORE_CERT_DATE_INVALID

Disables checking of SSL/PCT-based certificates for proper validity dates.

INTERNET_FLAG_IGNORE_REDIRECT_TO_HTTP

Disables detection of this special type of redirect. When this flag is used, WinINet functions transparently allow redirects from HTTPS to HTTP URLs.

INTERNET_FLAG_IGNORE_REDIRECT_TO_HTTPS

Disables detection of this special type of redirect. When this flag is used, WinINet functions transparently allow redirects from HTTP to HTTPS URLs.

INTERNET_FLAG_KEEP_CONNECTION

Uses keep-alive semantics, if available, for the connection. This flag is required for Microsoft Network (MSN), NT LAN Manager (NTLM), and other types of authentication.

INTERNET_FLAG_NEED_FILE

Causes a temporary file to be created if the file cannot be cached.

INTERNET_FLAG_NO_AUTH

Does not attempt authentication automatically.

INTERNET_FLAG_NO_AUTO_REDIRECT

Does not automatically handle redirection in HttpSendRequest.

INTERNET_FLAG_NO_CACHE_WRITE

Does not add the returned entity to the cache.

INTERNET_FLAG_NO_COOKIES

Does not automatically add cookie headers to requests, and does not automatically add returned cookies to the cookie database.

INTERNET_FLAG_NO_UI

Disables the cookie dialog box.

INTERNET_FLAG_PRAGMA_NOCACHE

Forces the request to be resolved by the origin server, even if a cached copy exists on the proxy.

INTERNET_FLAG_RELOAD

Forces a download of the requested file, object, or directory listing from the origin server, not from the cache.

INTERNET_FLAG_RESYNCHRONIZE

Reloads HTTP resources if the resource has been modified since the last time it was downloaded. All FTP resources are reloaded.

Windows XP and Windows Server 2003 R2 and earlier:  Gopher resources are also reloaded.
INTERNET_FLAG_SECURE

Uses secure transaction semantics. This translates to using Secure Sockets Layer/Private Communications Technology (SSL/PCT) and is only meaningful in HTTP requests.

 

dwContext [in]

A pointer to a variable that contains the application-defined value that associates this operation with any application data.

Return value

Returns an HTTP request handle if successful, or NULL otherwise. To retrieve extended error information, call GetLastError.

Remarks

HttpOpenRequest creates a new HTTP request handle and stores the specified parameters in that handle. An HTTP request handle holds a request to be sent to an HTTP server and contains all RFC822/MIME/HTTP headers to be sent as part of the request.

If a verb other than "GET" or "POST" is specified, HttpOpenRequest automatically sets INTERNET_FLAG_NO_CACHE_WRITE and INTERNET_FLAG_RELOAD for the request.

With Microsoft Internet Explorer 5 and later, if lpszVerb is set to "HEAD", the Content-Length header is ignored on responses from HTTP/1.1 servers.

After the calling application has finished using the HINTERNET handle returned by HttpOpenRequest, it must be closed using the InternetCloseHandle function.

Note   When a request is sent in asynchronous mode (the dwFlags parameter of InternetOpen specifies INTERNET_FLAG_ASYNC), and the dwContext parameter is zero (INTERNET_NO_CALLBACK), the callback function set with InternetSetStatusCallback on the request handle will not be invoked, however, the call will still be performed in asynchronous mode.

Like all other aspects of the WinINet API, this function cannot be safely called from within DllMain or the constructors and destructors of global objects.

Note  WinINet does not support server implementations. In addition, it should not be used from a service. For server implementations or services use Microsoft Windows HTTP Services (WinHTTP).

Requirements

Minimum supported client

Windows 2000 Professional

Minimum supported server

Windows 2000 Server

Header

Wininet.h

Library

Wininet.lib

DLL

Wininet.dll

Unicode and ANSI names

HttpOpenRequestW (Unicode) and HttpOpenRequestA (ANSI)

See also

HTTP Sessions
WinINet Functions

 

 

Send comments about this topic to Microsoft

Build date: 9/7/2011

Did you find this helpful?
(2000 characters remaining)
Community Content Add
Annotations FAQ
HttpOpenRequest returns NIL and GetLastError = 0
I have a problem with HttpOpenRequest return nil and getlastError=0. Is there anyway to tell what was the actual error?
WARNING: *lplpszAcceptTypes is a pointer to an ARRAY of strings, not to a single string
$0If you fail to pass a null-terminated array of string pointers, WinINET will crash.$0 http://nogeekhere.blogspot.com/2009/01/how-to-correctly-call-httpopenrequest.html
httpopenrequest not setting up target page and subdirectory
$0The problem in the code below is that it should be specifying the full path in the URL, not as a referer. $0 $0$0 $0 I am trying to post data to a web page using httpsend request from a windows mobile 5 application. I need to post it to a specific php page in a subdirectory. All the calls to setup an http request and sending it worked fine without any errors. But it had no effect at all. After lot of tries I realised that inspite of setting up the target page explicitly in httpopenrequest and mentioning the subdirectory, all the POST requests were being directed to the root default page. Just to check when I removed the root default page from web server and ran my code again the httpsendrequest reported 'object not found' error. $0 $0 here is my code $0 $0 staticTCHARhdrs[] = _T("Content-Type: application/x-www-form-urlencoded"); staticTCHARfrmdata[] = _T("year=79"); staticLPCTSTRaccept[2] = {L"*/*", NULL};$0 HINTERNEThSession = InternetOpen(_T("TestApp"), INTERNET_OPEN_TYPE_PRECONFIG, NULL, NULL, 0); errNum = GetLastError(); HINTERNEThConnect = InternetConnect(hSession, _T("www.myserver.com"), INTERNET_DEFAULT_HTTP_PORT, _T("xxxx"), _T("xxxxx"), INTERNET_SERVICE_HTTP, 0, NULL); errNum = GetLastError(); HINTERNEThRequest = HttpOpenRequest(hConnect, L"POST", L"/subdir/index.php", NULL, L"/subdir/", accept, 0, NULL); errNum = GetLastError(); size_tlenhdrs; StringCchLength(hdrs, STRSAFE_MAX_CCH, &lenhdrs); size_tlenfrmdata; StringCchLength(frmdata, STRSAFE_MAX_CCH, &lenfrmdata); HttpSendRequest(hRequest, hdrs, lenhdrs, frmdata, lenfrmdata);$0 DWORDdwSize = 2000, dwIndex = 0, dwStatus, dwStatusSize = sizeof(dwStatus); charbufIn[2000] = {'\0'}; HttpQueryInfo( hRequest, HTTP_QUERY_FLAG_NUMBER | HTTP_QUERY_STATUS_CODE, $0&dwStatus, &dwStatusSize, &dwIndex);$0