JohnOne Posted February 17, 2013 Posted February 17, 2013 Is there anything special which needs to be included in a web page (html, php, etc...) which allows it to respond to HTTP requests? code verbatim from msdn expandcollapse popupint _tmain(int argc, _TCHAR* argv[]) { DWORD dwSize = 0; DWORD dwDownloaded = 0; LPSTR pszOutBuffer; BOOL bResults = FALSE; HINTERNET hSession = NULL, hConnect = NULL, hRequest = NULL; // Use WinHttpOpen to obtain a session handle. hSession = WinHttpOpen( L"WinHTTP Example/1.0", WINHTTP_ACCESS_TYPE_DEFAULT_PROXY, WINHTTP_NO_PROXY_NAME, WINHTTP_NO_PROXY_BYPASS, 0); // Specify an HTTP server. if (hSession) hConnect = WinHttpConnect( hSession, L"www.google.com", INTERNET_DEFAULT_HTTPS_PORT, 0); // Create an HTTP request handle. if (hConnect) hRequest = WinHttpOpenRequest( hConnect, L"GET", NULL, NULL, WINHTTP_NO_REFERER, WINHTTP_DEFAULT_ACCEPT_TYPES, WINHTTP_FLAG_SECURE); // Send a request. if (hRequest) bResults = WinHttpSendRequest( hRequest, WINHTTP_NO_ADDITIONAL_HEADERS, 0, WINHTTP_NO_REQUEST_DATA, 0, 0, 0); // End the request. if (bResults) bResults = WinHttpReceiveResponse( hRequest, NULL); // Keep checking for data until there is nothing left. if (bResults) do { // Check for available data. dwSize = 0; if (!WinHttpQueryDataAvailable( hRequest, &dwSize)) printf("Error %u in WinHttpQueryDataAvailable.\n", GetLastError()); // Allocate space for the buffer. pszOutBuffer = new char[dwSize+1]; if (!pszOutBuffer) { printf("Out of memory\n"); dwSize=0; } else { // Read the Data. ZeroMemory(pszOutBuffer, dwSize+1); if (!WinHttpReadData( hRequest, (LPVOID)pszOutBuffer, dwSize, &dwDownloaded)) printf( "Error %u in WinHttpReadData.\n", GetLastError()); else printf( "%s\n", pszOutBuffer); // Free the memory allocated to the buffer. delete [] pszOutBuffer; } } while (dwSize > 0); // Report any errors. if (!bResults) printf("Error %d has occurred.\n", GetLastError()); // <-########### // Close any open handles. if (hRequest) WinHttpCloseHandle(hRequest); if (hConnect) WinHttpCloseHandle(hConnect); if (hSession) WinHttpCloseHandle(hSession); return 0; } When I try this, all works fine, but on another page with just a "line of text" it does not. the line indicated is printed. "Error 12175 has occured" WinINet failed to perform content decoding on the response. For more information, see the Content Encoding topic. I'm http complete noob. AutoIt Absolute Beginners Require a serial Pause Script Video Tutorials by Morthawt ipify Monkey's are, like, natures humans.
JohnOne Posted February 17, 2013 Author Posted February 17, 2013 (edited) In the page the error number pointed to, I read... "The Accept-Encoding header must be present in the request, and it must specify the gzip, deflate, or both gzip and deflate encoding schemes. The encoding scheme specified in the Content-Encoding header must match one of the encoding schemes specified in the Accept-Encoding header." What even is an "Accept-Encoding header". Obviously something to do with my problem. EDIT: I just downloaded some other library I found knocking about the internet that seems to work just fine. Thanks for looking anyway. Edited February 17, 2013 by JohnOne AutoIt Absolute Beginners Require a serial Pause Script Video Tutorials by Morthawt ipify Monkey's are, like, natures humans.
Richard Robertson Posted February 18, 2013 Posted February 18, 2013 Accept-Encoding is an HTTP parameter, which has nothing to do with the content itself. It has to do with the server encoding the data using a compression mechanism before transmission.
JohnOne Posted February 18, 2013 Author Posted February 18, 2013 Cheers. AutoIt Absolute Beginners Require a serial Pause Script Video Tutorials by Morthawt ipify Monkey's are, like, natures humans.
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now