Discussion:
HttpSendRequestEx Error
(too old to reply)
maxixi
2004-06-11 16:43:15 UTC
Permalink
Hi,

I use async mode to (cookie) logon a site and download resources.
Here is my code

// TestWinINet.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"

#include <windows.h>
#include <wininet.h>
#include <iostream.h>

void CALLBACK Callback(
HINTERNET hInternet,
DWORD_PTR dwContext,
DWORD dwInternetStatus,
LPVOID lpvStatusInformation,
DWORD dwStatusInformationLength
)
{
switch(dwContext) {
case 1:
cout << "Context 1 ";
switch (dwInternetStatus) {
case INTERNET_STATUS_HANDLE_CREATED:
cout << "INTERNET_STATUS_HANDLE_CREATED" << endl;
{
LPINTERNET_ASYNC_RESULT ret = (LPINTERNET_ASYNC_RESULT)
lpvStatusInformation;
HINTERNET m_hConnection = (HINTERNET)ret->dwResult;
HINTERNET m_hRequest = HttpOpenRequest(
m_hConnection, "POST", "/rss/login_main.rs",
NULL, NULL, NULL, INTERNET_FLAG_NO_CACHE_WRITE, 2);
}
break;
default:
break;
}
break;
case 2:
cout << "Context 2 ";
switch (dwInternetStatus) {
case INTERNET_STATUS_HANDLE_CREATED:
cout << "INTERNET_STATUS_HANDLE_CREATED" << endl;
{
LPINTERNET_ASYNC_RESULT ret = (LPINTERNET_ASYNC_RESULT)
lpvStatusInformation;
HINTERNET m_hRequest = (HINTERNET)ret->dwResult;

char pos[] = "uname=greenxiar&passwd=123456";
char hed[] = "Content-Type: application/x-www-form-urlencoded\r\n";

INTERNET_BUFFERS BufferIn;
memset(&BufferIn, 0, sizeof(BufferIn));
BufferIn.dwStructSize = sizeof(BufferIn);

BufferIn.lpvBuffer = NULL;
BufferIn.dwBufferTotal = strlen(pos);

BufferIn.lpcszHeader = hed;
BufferIn.dwHeadersLength = BufferIn.dwHeadersTotal = strlen(hed);

if (!HttpSendRequestEx(m_hRequest, &BufferIn, NULL, HSR_SYNC, 3))
{ cout << GetLastError() << endl; }
DWORD wd;
InternetWriteFile(m_hRequest, (void*) pos, strlen(pos), &wd);
}
break;
default:
break;
}
break;
case 3:
cout << "Context 3 ";
switch (dwInternetStatus) {
case INTERNET_STATUS_HANDLE_CREATED:
cout << "INTERNET_STATUS_HANDLE_CREATED" << endl;
{
LPINTERNET_ASYNC_RESULT ret = (LPINTERNET_ASYNC_RESULT)
lpvStatusInformation;
HINTERNET m_hRequest = (HINTERNET)ret->dwResult;
}
break;
default:
break;
}
}
}

int main(int argc, char* argv[])
{
HINTERNET m_hSession;
m_hSession = InternetOpen(NULL, INTERNET_OPEN_TYPE_PRECONFIG, 0, 0,
INTERNET_FLAG_ASYNC);
InternetSetStatusCallback(m_hSession, Callback);

HINTERNET m_hConnection;
m_hConnection = InternetConnect(m_hSession, "www.rongshuxia.com", 80,
NULL, NULL, INTERNET_SERVICE_HTTP, INTERNET_ASYN_FLAG, 1);

InternetCloseHandle(m_hSession);
return 0;
}

But I always failed when call HttpSendRequestEx and
received error 12019. What's wrong with my code?

Maxixi
Brian Combs
2004-06-17 14:46:27 UTC
Permalink
Take a look at the following article and see if that code works.

242019 SAMPLE: SendRequestExAsync Uses HttpSendRequestEx Asynchronously
http://support.microsoft.com/?id=242019

Thanks
Brian [MSFT]
Microsoft Developer Support
This posting is provided "AS IS" with no warranties, and confers no rights.
--------------------
| From: "maxixi" <***@1bitsoft.com>
| Subject: HttpSendRequestEx Error
| Date: Sat, 12 Jun 2004 00:43:15 +0800
| Lines: 112
| X-Priority: 3
| X-MSMail-Priority: Normal
| X-Newsreader: Microsoft Outlook Express 6.00.3790.0
| X-MimeOLE: Produced By Microsoft MimeOLE V6.00.3790.0
| Message-ID: <#***@TK2MSFTNGP11.phx.gbl>
| Newsgroups: microsoft.public.inetsdk.programming.wininet
| NNTP-Posting-Host: 211.158.98.63
| Path:
cpmsftngxa10.phx.gbl!TK2MSFTFEED01.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTNGP11
.phx.gbl
| Xref: cpmsftngxa10.phx.gbl
microsoft.public.inetsdk.programming.wininet:11465
| X-Tomcat-NG: microsoft.public.inetsdk.programming.wininet
|
| Hi,
|
| I use async mode to (cookie) logon a site and download resources.
| Here is my code
|
| // TestWinINet.cpp : Defines the entry point for the console application.
| //
|
| #include "stdafx.h"
|
| #include <windows.h>
| #include <wininet.h>
| #include <iostream.h>
|
| void CALLBACK Callback(
| HINTERNET hInternet,
| DWORD_PTR dwContext,
| DWORD dwInternetStatus,
| LPVOID lpvStatusInformation,
| DWORD dwStatusInformationLength
| )
| {
| switch(dwContext) {
| case 1:
| cout << "Context 1 ";
| switch (dwInternetStatus) {
| case INTERNET_STATUS_HANDLE_CREATED:
| cout << "INTERNET_STATUS_HANDLE_CREATED" << endl;
| {
| LPINTERNET_ASYNC_RESULT ret = (LPINTERNET_ASYNC_RESULT)
| lpvStatusInformation;
| HINTERNET m_hConnection = (HINTERNET)ret->dwResult;
| HINTERNET m_hRequest = HttpOpenRequest(
| m_hConnection, "POST", "/rss/login_main.rs",
| NULL, NULL, NULL, INTERNET_FLAG_NO_CACHE_WRITE, 2);
| }
| break;
| default:
| break;
| }
| break;
| case 2:
| cout << "Context 2 ";
| switch (dwInternetStatus) {
| case INTERNET_STATUS_HANDLE_CREATED:
| cout << "INTERNET_STATUS_HANDLE_CREATED" << endl;
| {
| LPINTERNET_ASYNC_RESULT ret = (LPINTERNET_ASYNC_RESULT)
| lpvStatusInformation;
| HINTERNET m_hRequest = (HINTERNET)ret->dwResult;
|
| char pos[] = "uname=greenxiar&passwd=123456";
| char hed[] = "Content-Type: application/x-www-form-urlencoded\r\n";
|
| INTERNET_BUFFERS BufferIn;
| memset(&BufferIn, 0, sizeof(BufferIn));
| BufferIn.dwStructSize = sizeof(BufferIn);
|
| BufferIn.lpvBuffer = NULL;
| BufferIn.dwBufferTotal = strlen(pos);
|
| BufferIn.lpcszHeader = hed;
| BufferIn.dwHeadersLength = BufferIn.dwHeadersTotal = strlen(hed);
|
| if (!HttpSendRequestEx(m_hRequest, &BufferIn, NULL, HSR_SYNC, 3))
| { cout << GetLastError() << endl; }
| DWORD wd;
| InternetWriteFile(m_hRequest, (void*) pos, strlen(pos), &wd);
| }
| break;
| default:
| break;
| }
| break;
| case 3:
| cout << "Context 3 ";
| switch (dwInternetStatus) {
| case INTERNET_STATUS_HANDLE_CREATED:
| cout << "INTERNET_STATUS_HANDLE_CREATED" << endl;
| {
| LPINTERNET_ASYNC_RESULT ret = (LPINTERNET_ASYNC_RESULT)
| lpvStatusInformation;
| HINTERNET m_hRequest = (HINTERNET)ret->dwResult;
| }
| break;
| default:
| break;
| }
| }
| }
|
| int main(int argc, char* argv[])
| {
| HINTERNET m_hSession;
| m_hSession = InternetOpen(NULL, INTERNET_OPEN_TYPE_PRECONFIG, 0, 0,
| INTERNET_FLAG_ASYNC);
| InternetSetStatusCallback(m_hSession, Callback);
|
| HINTERNET m_hConnection;
| m_hConnection = InternetConnect(m_hSession, "www.rongshuxia.com", 80,
| NULL, NULL, INTERNET_SERVICE_HTTP, INTERNET_ASYN_FLAG, 1);
|
| InternetCloseHandle(m_hSession);
| return 0;
| }
|
| But I always failed when call HttpSendRequestEx and
| received error 12019. What's wrong with my code?
|
| Maxixi
|
|
|
maxixi
2004-06-17 15:51:11 UTC
Permalink
Thanks Brian!
Post by Brian Combs
Take a look at the following article and see if that code works.
242019 SAMPLE: SendRequestExAsync Uses HttpSendRequestEx Asynchronously
http://support.microsoft.com/?id=242019
Thanks
Brian [MSFT]
Microsoft Developer Support
This posting is provided "AS IS" with no warranties, and confers no rights.
--------------------
| Subject: HttpSendRequestEx Error
| Date: Sat, 12 Jun 2004 00:43:15 +0800
| Lines: 112
| X-Priority: 3
| X-MSMail-Priority: Normal
| X-Newsreader: Microsoft Outlook Express 6.00.3790.0
| X-MimeOLE: Produced By Microsoft MimeOLE V6.00.3790.0
| Newsgroups: microsoft.public.inetsdk.programming.wininet
| NNTP-Posting-Host: 211.158.98.63
cpmsftngxa10.phx.gbl!TK2MSFTFEED01.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTNGP11
Post by Brian Combs
phx.gbl
| Xref: cpmsftngxa10.phx.gbl
microsoft.public.inetsdk.programming.wininet:11465
| X-Tomcat-NG: microsoft.public.inetsdk.programming.wininet
|
| Hi,
|
| I use async mode to (cookie) logon a site and download resources.
| Here is my code
|
| // TestWinINet.cpp : Defines the entry point for the console
application.
Post by Brian Combs
| //
|
| #include "stdafx.h"
|
| #include <windows.h>
| #include <wininet.h>
| #include <iostream.h>
|
| void CALLBACK Callback(
| HINTERNET hInternet,
| DWORD_PTR dwContext,
| DWORD dwInternetStatus,
| LPVOID lpvStatusInformation,
| DWORD dwStatusInformationLength
| )
| {
| switch(dwContext) {
| cout << "Context 1 ";
| switch (dwInternetStatus) {
| cout << "INTERNET_STATUS_HANDLE_CREATED" << endl;
| {
| LPINTERNET_ASYNC_RESULT ret = (LPINTERNET_ASYNC_RESULT)
| lpvStatusInformation;
| HINTERNET m_hConnection = (HINTERNET)ret->dwResult;
| HINTERNET m_hRequest = HttpOpenRequest(
| m_hConnection, "POST", "/rss/login_main.rs",
| NULL, NULL, NULL, INTERNET_FLAG_NO_CACHE_WRITE, 2);
| }
| break;
| break;
| }
| break;
| cout << "Context 2 ";
| switch (dwInternetStatus) {
| cout << "INTERNET_STATUS_HANDLE_CREATED" << endl;
| {
| LPINTERNET_ASYNC_RESULT ret = (LPINTERNET_ASYNC_RESULT)
| lpvStatusInformation;
| HINTERNET m_hRequest = (HINTERNET)ret->dwResult;
|
| char pos[] = "uname=greenxiar&passwd=123456";
| char hed[] = "Content-Type: application/x-www-form-urlencoded\r\n";
|
| INTERNET_BUFFERS BufferIn;
| memset(&BufferIn, 0, sizeof(BufferIn));
| BufferIn.dwStructSize = sizeof(BufferIn);
|
| BufferIn.lpvBuffer = NULL;
| BufferIn.dwBufferTotal = strlen(pos);
|
| BufferIn.lpcszHeader = hed;
| BufferIn.dwHeadersLength = BufferIn.dwHeadersTotal = strlen(hed);
|
| if (!HttpSendRequestEx(m_hRequest, &BufferIn, NULL, HSR_SYNC, 3))
| { cout << GetLastError() << endl; }
| DWORD wd;
| InternetWriteFile(m_hRequest, (void*) pos, strlen(pos), &wd);
| }
| break;
| break;
| }
| break;
| cout << "Context 3 ";
| switch (dwInternetStatus) {
| cout << "INTERNET_STATUS_HANDLE_CREATED" << endl;
| {
| LPINTERNET_ASYNC_RESULT ret = (LPINTERNET_ASYNC_RESULT)
| lpvStatusInformation;
| HINTERNET m_hRequest = (HINTERNET)ret->dwResult;
| }
| break;
| break;
| }
| }
| }
|
| int main(int argc, char* argv[])
| {
| HINTERNET m_hSession;
| m_hSession = InternetOpen(NULL, INTERNET_OPEN_TYPE_PRECONFIG, 0, 0,
| INTERNET_FLAG_ASYNC);
| InternetSetStatusCallback(m_hSession, Callback);
|
| HINTERNET m_hConnection;
| m_hConnection = InternetConnect(m_hSession, "www.rongshuxia.com", 80,
| NULL, NULL, INTERNET_SERVICE_HTTP, INTERNET_ASYN_FLAG, 1);
|
| InternetCloseHandle(m_hSession);
| return 0;
| }
|
| But I always failed when call HttpSendRequestEx and
| received error 12019. What's wrong with my code?
|
| Maxixi
|
|
|
Loading...