Discussion:
HttpOpenRequest problemes
(too old to reply)
Iulia
2008-05-07 15:58:00 UTC
Permalink
Hello.
Please, I would really need some help with wininet functions. I have a
project in Visual Studio 2005 that uses the Visual Studio’s server. When it
is executing, it listens on the 7000 port at the address:
http://www.fabrikam.com:7000/sample/trust/usernamepassword/sts . I can target
this address with telnet.

The important parts of my code are:

//******** code beginning ********
//req_token is a string I want to send as a message atached to a POST request

HINTERNET internet_open = InternetOpen(_T("cardspace-proxy"),
INTERNET_OPEN_TYPE_PRECONFIG, NULL, NULL, 0);

HINTERNET internet_connect = InternetConnect(internet_open,
"www.fabrikam.com", 7000, NULL, NULL, INTERNET_SERVICE_HTTP, 0, 0);

char *types=(char*)malloc(strlen("application/soap+xml") + 2);
strcpy(types,"application/soap+xml");
types[strlen("application/soap+xml") + 1 ] = 0;

HINTERNET open_request = HttpOpenRequest(internet_connect, "POST",
"/sample/trust/usernamepassword/sts", "HTTP/1.1", NULL, (const char**)
&types, INTERNET_FLAG_RELOAD, NULL);

char buf[7];
sprintf(buf,"%d",req_tok.length());

string header = "Content-Type: application/soap+xml; charset=utf-8; Host:
www.fabrikam.com:7000; Content-Length: ";
header += buf;
header += "; Expect: 100-continue";

if ( !HttpSendRequest( open_request, header.c_str(), header.length(),
(void*)req_tok.c_str(), req_tok.length()) )
{…}

if ( !HttpQueryInfo (open_request, HTTP_QUERY_STATUS_CODE, szSatusCode,
&dwInfoBufferSize, NULL) )
{…}

if( !InternetQueryDataAvailable( open_request,&dwNumberOfBytesAvailable, 0,
0) )
{…}

if( !InternetReadFile( open_request, lpBuffer, dwNumberOfBytesAvailable,
&dwNumberOfBytesRead))
{…}

//******** code end ********

The error is: “HttpSendRequest failed; Error: 12002”. I searched and 12002
means that the request has timed out. I really don’t understand why it
doesn’t work.

Thank you.
Iulia
Volodymyr M. Shcherbyna
2008-05-08 08:32:17 UTC
Permalink
Sounds like an issue with the server, because the simplest version of your
code works fine when doing connections to www.fabrikam.com port 80. Did you
tried to look at the logs on server side when you're connecting to 7000
port?

Here comes the simplified version of your code, that I used to test:

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

#pragma comment(lib, "wininet.lib")

int _tmain(int argc, _TCHAR* argv[])
{
HINTERNET hInternet = NULL;
HINTERNET hConnect = NULL;
HINTERNET hRequest = NULL;
BOOL bRetVal = TRUE;

hInternet = InternetOpen(TEXT("cardspace-proxy"),
INTERNET_OPEN_TYPE_PRECONFIG, NULL, NULL, 0);

if (hInternet == NULL)
{
return FALSE;
}

hConnect = InternetConnect(hInternet, TEXT("www.fabrikam.com"), 80, NULL,
NULL, INTERNET_SERVICE_HTTP, 0, 0);

if (hConnect == NULL)
{
InternetCloseHandle(hInternet);

return FALSE;
}

hRequest = HttpOpenRequest(hConnect, TEXT("POST"),
TEXT("/sample/trust/usernamepassword/sts"), TEXT("HTTP/1.1"), NULL, NULL,
INTERNET_FLAG_RELOAD, NULL);

if (hRequest == NULL)
{
InternetCloseHandle(hConnect);
InternetCloseHandle(hInternet);

return FALSE;
}

bRetVal = HttpSendRequest(hRequest, NULL, 0, NULL, 0);

InternetCloseHandle(hRequest);
InternetCloseHandle(hConnect);
InternetCloseHandle(hInternet);
}
--
V.
This posting is provided "AS IS" with no warranties, and confers no
rights.
Post by Iulia
Hello.
Please, I would really need some help with wininet functions. I have a
project in Visual Studio 2005 that uses the Visual Studio's server. When
it
http://www.fabrikam.com:7000/sample/trust/usernamepassword/sts . I can target
this address with telnet.
//******** code beginning ********
//req_token is a string I want to send as a message atached to a POST request
HINTERNET internet_open = InternetOpen(_T("cardspace-proxy"),
INTERNET_OPEN_TYPE_PRECONFIG, NULL, NULL, 0);
HINTERNET internet_connect = InternetConnect(internet_open,
"www.fabrikam.com", 7000, NULL, NULL, INTERNET_SERVICE_HTTP, 0, 0);
char *types=(char*)malloc(strlen("application/soap+xml") + 2);
strcpy(types,"application/soap+xml");
types[strlen("application/soap+xml") + 1 ] = 0;
HINTERNET open_request = HttpOpenRequest(internet_connect, "POST",
"/sample/trust/usernamepassword/sts", "HTTP/1.1", NULL, (const char**)
&types, INTERNET_FLAG_RELOAD, NULL);
char buf[7];
sprintf(buf,"%d",req_tok.length());
www.fabrikam.com:7000; Content-Length: ";
header += buf;
header += "; Expect: 100-continue";
if ( !HttpSendRequest( open_request, header.c_str(), header.length(),
(void*)req_tok.c_str(), req_tok.length()) )
{:}
if ( !HttpQueryInfo (open_request, HTTP_QUERY_STATUS_CODE, szSatusCode,
&dwInfoBufferSize, NULL) )
{:}
if( !InternetQueryDataAvailable( open_request,&dwNumberOfBytesAvailable, 0,
0) )
{:}
if( !InternetReadFile( open_request, lpBuffer, dwNumberOfBytesAvailable,
&dwNumberOfBytesRead))
{:}
//******** code end ********
The error is: "HttpSendRequest failed; Error: 12002". I searched and 12002
means that the request has timed out. I really don't understand why it
doesn't work.
Thank you.
Iulia
Volodymyr M. Shcherbyna
2008-05-08 08:38:20 UTC
Permalink
As an additional you can also use wireshark to see the traces between client
and the server and see what's wrong.
--
V.
This posting is provided "AS IS" with no warranties, and confers no
rights.
Post by Volodymyr M. Shcherbyna
Sounds like an issue with the server, because the simplest version of your
code works fine when doing connections to www.fabrikam.com port 80. Did
you tried to look at the logs on server side when you're connecting to
7000 port?
#include <windows.h>
#include <wininet.h>
#pragma comment(lib, "wininet.lib")
int _tmain(int argc, _TCHAR* argv[])
{
HINTERNET hInternet = NULL;
HINTERNET hConnect = NULL;
HINTERNET hRequest = NULL;
BOOL bRetVal = TRUE;
hInternet = InternetOpen(TEXT("cardspace-proxy"),
INTERNET_OPEN_TYPE_PRECONFIG, NULL, NULL, 0);
if (hInternet == NULL)
{
return FALSE;
}
hConnect = InternetConnect(hInternet, TEXT("www.fabrikam.com"), 80, NULL,
NULL, INTERNET_SERVICE_HTTP, 0, 0);
if (hConnect == NULL)
{
InternetCloseHandle(hInternet);
return FALSE;
}
hRequest = HttpOpenRequest(hConnect, TEXT("POST"),
TEXT("/sample/trust/usernamepassword/sts"), TEXT("HTTP/1.1"), NULL, NULL,
INTERNET_FLAG_RELOAD, NULL);
if (hRequest == NULL)
{
InternetCloseHandle(hConnect);
InternetCloseHandle(hInternet);
return FALSE;
}
bRetVal = HttpSendRequest(hRequest, NULL, 0, NULL, 0);
InternetCloseHandle(hRequest);
InternetCloseHandle(hConnect);
InternetCloseHandle(hInternet);
}
--
V.
This posting is provided "AS IS" with no warranties, and confers no
rights.
Post by Iulia
Hello.
Please, I would really need some help with wininet functions. I have a
project in Visual Studio 2005 that uses the Visual Studio's server. When
it
http://www.fabrikam.com:7000/sample/trust/usernamepassword/sts . I can target
this address with telnet.
//******** code beginning ********
//req_token is a string I want to send as a message atached to a POST request
HINTERNET internet_open = InternetOpen(_T("cardspace-proxy"),
INTERNET_OPEN_TYPE_PRECONFIG, NULL, NULL, 0);
HINTERNET internet_connect = InternetConnect(internet_open,
"www.fabrikam.com", 7000, NULL, NULL, INTERNET_SERVICE_HTTP, 0, 0);
char *types=(char*)malloc(strlen("application/soap+xml") + 2);
strcpy(types,"application/soap+xml");
types[strlen("application/soap+xml") + 1 ] = 0;
HINTERNET open_request = HttpOpenRequest(internet_connect, "POST",
"/sample/trust/usernamepassword/sts", "HTTP/1.1", NULL, (const char**)
&types, INTERNET_FLAG_RELOAD, NULL);
char buf[7];
sprintf(buf,"%d",req_tok.length());
www.fabrikam.com:7000; Content-Length: ";
header += buf;
header += "; Expect: 100-continue";
if ( !HttpSendRequest( open_request, header.c_str(), header.length(),
(void*)req_tok.c_str(), req_tok.length()) )
{:}
if ( !HttpQueryInfo (open_request, HTTP_QUERY_STATUS_CODE, szSatusCode,
&dwInfoBufferSize, NULL) )
{:}
if( !InternetQueryDataAvailable( open_request,&dwNumberOfBytesAvailable, 0,
0) )
{:}
if( !InternetReadFile( open_request, lpBuffer, dwNumberOfBytesAvailable,
&dwNumberOfBytesRead))
{:}
//******** code end ********
The error is: "HttpSendRequest failed; Error: 12002". I searched and 12002
means that the request has timed out. I really don't understand why it
doesn't work.
Thank you.
Iulia
Iulia
2008-06-27 15:49:06 UTC
Permalink
Thank you for your answer. I don’t know why, but my code doesn’t work if I
use
HINTERNET internet_connect = InternetConnect(internet_open,
TEXT("www.fabrikam.com"), 7000, NULL, NULL, INTERNET_SERVICE_HTTP, 0, 1).

I am obliged to use
HINTERNET internet_connect = InternetConnect(internet_open,
TEXT("127.0.0.1"), 7000, NULL, NULL, INTERNET_SERVICE_HTTP, 0, 1).

“www.fabrikam.com” is another name for localhost.

I also have another problem. I first want to send to the server of Visual
Studio the header of a POST request, containing “Expect: 100-continue”, wait
for a “HTTP/1.1 100 Continue” and then send the body of the request, which is
a SOAP message. But with wininet functions I only know how to send the header
and the body of the request at the same time, using "HttpSendRequest". I
think that the server wants to respond with a “HTTP/1.1 100 Continue” before
receiving the body of the message and this is why it doesn’t return the
message I want, instead he is signalizing a “500 Internal Server Error“.

Thank you.
Iulia

Loading...