Discussion:
HttpOpenRequest and HttpSendRequest
(too old to reply)
satishsuman
2008-04-01 14:39:00 UTC
Permalink
I am trying to make a HTTP connection with web server and trying to pass
authentication information.

I included INet.h.

My code for http request is..

***************************************************************************************
HINTERNET hSession = ::InternetOpen("SomeName",
PRE_CONFIG_INTERNET_ACCESS,
NULL,
INTERNET_INVALID_PORT_NUMBER,
0) ;

HINTERNET hConnect = ::InternetConnect(hSession,
"http://localhost/login",
INTERNET_DEFAULT_HTTP_PORT,
user_id,
password,
INTERNET_SERVICE_HTTP,
0,
0) ;

SetLastError(0);
HINTERNET hHttpFile = ::HttpOpenRequest(hConnect,
"POST",
"",
HTTP_VERSION,
NULL,
0,
INTERNET_FLAG_DONT_CACHE,
0);

if(hHttpFile)
{
DWORD dwErr = GetLastError();
char message[1000];
sprintf(message, "Ya! Success! - Error = %u", dwErr);
MessageBox(NULL, message, "HttpOpenRequest", MB_OK);
}
else
{
DWORD dwErr = GetLastError();
char message[1000];
sprintf(message, "No! Failure! - Error = %u", dwErr);
MessageBox(NULL, message, "HttpOpenRequest", MB_OK);
}

INTERNET_BUFFERS inBuf;
inBuf.dwStructSize = sizeof(INTERNET_BUFFERS);
inBuf.Next = NULL;
inBuf.lpcszHeader = NULL;
inBuf.dwHeadersLength = 0;
inBuf.dwHeadersTotal = 0;

char postData[1000];
sprintf(postData, "user_id=%s&password=%s", user_id, password);
inBuf.lpvBuffer = postData;
inBuf.dwBufferLength = strlen(postData);
inBuf.dwBufferTotal = strlen(postData);

inBuf.dwOffsetLow = 0;
inBuf.dwOffsetHigh = 0;

INTERNET_BUFFERS outBuf;
outBuf.dwStructSize = sizeof(INTERNET_BUFFERS);
outBuf.Next = NULL;
outBuf.lpcszHeader = NULL;
outBuf.dwHeadersLength = 0;
outBuf.dwHeadersTotal = 0;
outBuf.lpvBuffer = new char[1000];
outBuf.dwBufferLength = 1000;
outBuf.dwBufferTotal = 1000;
outBuf.dwOffsetLow = 0;
outBuf.dwOffsetHigh = 0;

SetLastError(0);


BOOL bSendRequest = ::HttpSendRequestEx(hHttpFile, &inBuf, &outBuf,
HSR_SYNC, NULL);


if(bSendRequest)
{
DWORD dwErr = GetLastError();
char message[1000];
sprintf(message, "Ya! Success! - Error = %u", dwErr);
MessageBox(NULL, message, "HttpSendRequest", MB_OK);
}
else
{
DWORD dwErr = GetLastError();
char message[1000];
sprintf(message, "No! Failure! - Error = %u", dwErr);
MessageBox(NULL, message, "HttpSendRequest", MB_OK);
}


*****************************************************************************************************************
HttpOpenRequest works an return message is Ya! Success! Error = 122
HttpSendRequestEx goes in else and gives message No! Failure! Error = 87.

What is wrong with my code?
Volodymyr M. Shcherbyna
2008-04-02 14:08:08 UTC
Permalink
[...]
Post by satishsuman
HttpOpenRequest works an return message is Ya! Success! Error = 122
First, you have to understand, that if the function returns TRUE, there is
no need to look at error code - it does not have meaning.
Post by satishsuman
HttpSendRequestEx goes in else and gives message No! Failure! Error = 87.
I bet you got errors just because LPINTERNET_BUFFERS lpBuffersOut for
HttpSendRequestEx is reserved, and should be NULL. Also, you do not pass
correct url into InternetConnect. It should be withOUT http://.

I will attach a complete working source code in next message. You will be
able to download the source code if you use Outlook Express.
--
V.
This posting is provided "AS IS" with no warranties, and confers no
rights.
Post by satishsuman
I am trying to make a HTTP connection with web server and trying to pass
authentication information.
I included INet.h.
My code for http request is..
***************************************************************************************
HINTERNET hSession = ::InternetOpen("SomeName",
PRE_CONFIG_INTERNET_ACCESS,
NULL,
INTERNET_INVALID_PORT_NUMBER,
0) ;
HINTERNET hConnect = ::InternetConnect(hSession,
"http://localhost/login",
INTERNET_DEFAULT_HTTP_PORT,
user_id,
password,
INTERNET_SERVICE_HTTP,
0,
0) ;
SetLastError(0);
HINTERNET hHttpFile = ::HttpOpenRequest(hConnect,
"POST",
"",
HTTP_VERSION,
NULL,
0,
INTERNET_FLAG_DONT_CACHE,
0);
if(hHttpFile)
{
DWORD dwErr = GetLastError();
char message[1000];
sprintf(message, "Ya! Success! - Error = %u", dwErr);
MessageBox(NULL, message, "HttpOpenRequest", MB_OK);
}
else
{
DWORD dwErr = GetLastError();
char message[1000];
sprintf(message, "No! Failure! - Error = %u", dwErr);
MessageBox(NULL, message, "HttpOpenRequest", MB_OK);
}
INTERNET_BUFFERS inBuf;
inBuf.dwStructSize = sizeof(INTERNET_BUFFERS);
inBuf.Next = NULL;
inBuf.lpcszHeader = NULL;
inBuf.dwHeadersLength = 0;
inBuf.dwHeadersTotal = 0;
char postData[1000];
sprintf(postData, "user_id=%s&password=%s", user_id, password);
inBuf.lpvBuffer = postData;
inBuf.dwBufferLength = strlen(postData);
inBuf.dwBufferTotal = strlen(postData);
inBuf.dwOffsetLow = 0;
inBuf.dwOffsetHigh = 0;
INTERNET_BUFFERS outBuf;
outBuf.dwStructSize = sizeof(INTERNET_BUFFERS);
outBuf.Next = NULL;
outBuf.lpcszHeader = NULL;
outBuf.dwHeadersLength = 0;
outBuf.dwHeadersTotal = 0;
outBuf.lpvBuffer = new char[1000];
outBuf.dwBufferLength = 1000;
outBuf.dwBufferTotal = 1000;
outBuf.dwOffsetLow = 0;
outBuf.dwOffsetHigh = 0;
SetLastError(0);
BOOL bSendRequest = ::HttpSendRequestEx(hHttpFile, &inBuf, &outBuf,
HSR_SYNC, NULL);
if(bSendRequest)
{
DWORD dwErr = GetLastError();
char message[1000];
sprintf(message, "Ya! Success! - Error = %u", dwErr);
MessageBox(NULL, message, "HttpSendRequest", MB_OK);
}
else
{
DWORD dwErr = GetLastError();
char message[1000];
sprintf(message, "No! Failure! - Error = %u", dwErr);
MessageBox(NULL, message, "HttpSendRequest", MB_OK);
}
*****************************************************************************************************************
HttpOpenRequest works an return message is Ya! Success! Error = 122
HttpSendRequestEx goes in else and gives message No! Failure! Error = 87.
What is wrong with my code?
Volodymyr M. Shcherbyna
2008-04-02 14:10:29 UTC
Permalink
Attached is the source code.
--
V.
This posting is provided "AS IS" with no warranties, and confers no
rights.
Post by Volodymyr M. Shcherbyna
[...]
Post by satishsuman
HttpOpenRequest works an return message is Ya! Success! Error = 122
First, you have to understand, that if the function returns TRUE, there is
no need to look at error code - it does not have meaning.
Post by satishsuman
HttpSendRequestEx goes in else and gives message No! Failure! Error = 87.
I bet you got errors just because LPINTERNET_BUFFERS lpBuffersOut for
HttpSendRequestEx is reserved, and should be NULL. Also, you do not pass
correct url into InternetConnect. It should be withOUT http://.
I will attach a complete working source code in next message. You will be
able to download the source code if you use Outlook Express.
--
V.
This posting is provided "AS IS" with no warranties, and confers no
rights.
Post by satishsuman
I am trying to make a HTTP connection with web server and trying to pass
authentication information.
I included INet.h.
My code for http request is..
***************************************************************************************
HINTERNET hSession = ::InternetOpen("SomeName",
PRE_CONFIG_INTERNET_ACCESS,
NULL,
INTERNET_INVALID_PORT_NUMBER,
0) ;
HINTERNET hConnect = ::InternetConnect(hSession,
"http://localhost/login",
INTERNET_DEFAULT_HTTP_PORT,
user_id,
password,
INTERNET_SERVICE_HTTP,
0,
0) ;
SetLastError(0);
HINTERNET hHttpFile = ::HttpOpenRequest(hConnect,
"POST",
"",
HTTP_VERSION,
NULL,
0,
INTERNET_FLAG_DONT_CACHE,
0);
if(hHttpFile)
{
DWORD dwErr = GetLastError();
char message[1000];
sprintf(message, "Ya! Success! - Error = %u", dwErr);
MessageBox(NULL, message, "HttpOpenRequest", MB_OK);
}
else
{
DWORD dwErr = GetLastError();
char message[1000];
sprintf(message, "No! Failure! - Error = %u", dwErr);
MessageBox(NULL, message, "HttpOpenRequest", MB_OK);
}
INTERNET_BUFFERS inBuf;
inBuf.dwStructSize = sizeof(INTERNET_BUFFERS);
inBuf.Next = NULL;
inBuf.lpcszHeader = NULL;
inBuf.dwHeadersLength = 0;
inBuf.dwHeadersTotal = 0;
char postData[1000];
sprintf(postData, "user_id=%s&password=%s", user_id, password);
inBuf.lpvBuffer = postData;
inBuf.dwBufferLength = strlen(postData);
inBuf.dwBufferTotal = strlen(postData);
inBuf.dwOffsetLow = 0;
inBuf.dwOffsetHigh = 0;
INTERNET_BUFFERS outBuf;
outBuf.dwStructSize = sizeof(INTERNET_BUFFERS);
outBuf.Next = NULL;
outBuf.lpcszHeader = NULL;
outBuf.dwHeadersLength = 0;
outBuf.dwHeadersTotal = 0;
outBuf.lpvBuffer = new char[1000];
outBuf.dwBufferLength = 1000;
outBuf.dwBufferTotal = 1000;
outBuf.dwOffsetLow = 0;
outBuf.dwOffsetHigh = 0;
SetLastError(0);
BOOL bSendRequest = ::HttpSendRequestEx(hHttpFile, &inBuf, &outBuf,
HSR_SYNC, NULL);
if(bSendRequest)
{
DWORD dwErr = GetLastError();
char message[1000];
sprintf(message, "Ya! Success! - Error = %u", dwErr);
MessageBox(NULL, message, "HttpSendRequest", MB_OK);
}
else
{
DWORD dwErr = GetLastError();
char message[1000];
sprintf(message, "No! Failure! - Error = %u", dwErr);
MessageBox(NULL, message, "HttpSendRequest", MB_OK);
}
*****************************************************************************************************************
HttpOpenRequest works an return message is Ya! Success! Error = 122
HttpSendRequestEx goes in else and gives message No! Failure! Error = 87.
What is wrong with my code?
begin 666 src.cpp
M(VEN8VQU9&4@(G-T9&%F>"YH(@T*#0HC:6YC;'5D92 \=VEN9&]W<RYH/@T*
M(VEN8VQU9&4@/'=I;FEN970N:#X-"B-I;F-L=61E(#QM86QL;V,N:#X-"@T*
M(W!R86=M82!C;VUM96YT("AL:6(L(")W:6YI;F5T+FQI8B(I#0H-"G9O:60@
M;6%I;BAV;VED*0T*>PT*(V1E9FEN92!U<V5R7VED"0E415A4*")5<V5R(BD-
M"B-D969I;F4@<&%S<W=O<F0)5$585"@B4'=D(BD-"B-D969I;F4@=7)L"0D)
M5$585"@B,3DR+C$V."XP+C$Q(BD-"@T*"4A)3E1%4DY%5"!H4V5S<VEO;B ]
M($EN=&5R;F5T3W!E;BA415A4*")3;VUE3F%M92(I+"!04D5?0T].1DE'7TE.
M5$523D547T%#***@3E5,3"***@3E5,3"P@,"D[#0H-"@EI9B H:%-E<W-I
M;VX@/***@3E5,3"D-"@E[#0H)"7!R:6YT9B H(D5R<F]R(')E='5R;F5D(&%F
M=&5R($EN=&5R;F5T3W!E;B!C86QL.B E9%QN(***@1V5T3&%S=$5R<F]R*"DI
M.PT*"0ER971U<FX[#0H)?0T*#0H@(" @2$E.5$523D54(&A#;VYN96-T(#T@
M26YT97)N971#;VYN96-T*&A397-S:6]N+"!U<FPL($E.5$523D547T1%1D%5
M3%1?2%144%]03U)4+"!.54Q,+"!.54Q,+"!)3E1%4DY%5%]315)624-%7TA4
M5% L(# L(# I.PT*#0H):68@*&A#;VYN96-T(#T]($Y53$PI#0H)>PT*"0EP
M<FEN=&8@*")%<G)O<B!R971U<FYE9"!A9G1E<B!);G1E<FYE=$-O;FYE8W0@
M8V%L;#H@)61<;B(L($=E=$QA<W1%<G)O<***@I*3L-"@D)<F5T=7)N.PT*"7T-
M"@T*(" @($A)3E1%4DY%5"!H2'1T<$9I;&4@/2!(='1P3W!E;E)E<75E<W0H
M:$-O;FYE8W0L(%1%6%0H(E!/4U0B****@3E5,3"***@2%144%]615)324].+"!.
M54Q,+" P+"!)3E1%4DY%5%]&3$%'7T1/3E1?0T%#2$4L(# I.PT*#0H):68@
M*&A(='1P1FEL92 ]/2!.54Q,*0T*"7L-"@D)<')I;G1F("@B17)R;W(@<F5T
M=7)***@869T97(@2'1T<$]P96Y297%U97-T(&-A;&PZ("5D7&XB+"!'971,
M87-T17)R;W(H*2D[#0H)"7)E='5R;CL-"@E]#0H-"@E)3E1%4DY%5%]"549&
M15)3(&EN0G5F(#T@>S!].PT*#0H@(" @:6Y"=68N9'=3=')U8W13:7IE"0D)
M/2!S:7IE;V8H24Y415).151?0E5&1D524RD[#0H@(" @:6Y"=68N3F5X= D)
M"0D)/2!.54Q,.PT*(" @(&EN0G5F+FQP8W-Z2&5A9&5R"0D)/2!.54Q,.PT*
M(" @(&EN0G5F+F1W2&5A9&5R<TQE;F=T: D)/2 P.PT*(" @(&EN0G5F+F1W
M2&5A9&5R<U1O=&%L"0D](# [#0H-"@E40TA!4B!P;W-T1&%T85LQ,# P70D)
M/2![,'T[#0H-"B @("!S=W!R:6YT9BAP;W-T1&%***@5$585"@B=7-E<E]I
M9#TE<R9P87-S=V]R9#TE<R(I+"!U<V5R7VED+"!P87-S=V]R9"D[#0H-"B @
M("!I;D)U9BYL<'9"=69F97()"0D)/2!P;W-T1&%T83L-"B @("!I;D)U9BYD
M=T)U9F9E<DQE;F=T: D)/2 H7W1C<VQE;BAP;W-T1&%T82D@*B!S:7IE;V8H
M5$-(05(I*3L-"B @("!I;D)U9BYD=T)U9F9E<E1O=&%L"0D)/2!I;D)U9BYD
M=T)U9F9E<DQE;F=T:#L-"@T*(" @(&EN0G5F+F1W3V9F<V5T3&]W"0D)/2 P
M.R -"B @("!I;D)U9BYD=T]F9G-E=$AI9V@)"0D](# [#0H-"B @("!"3T],
M(&)396YD4F5Q=65S=" ]($AT='!396YD4F5Q=65S=$5X*&A(='1P1FEL92P@
M)FEN0G5F+"!.54Q,+"!(4U)?***@3E5,3"D[#0H-"B @("!I9B H8E-E
M;F1297%U97-T(#T]($9!3%-%*0T*(" @('L-"@D)<')I;G1F("@B17)R;W(@
M<F5T=7)***@869T97(@2'1T<%-E;F1297%U97-T17@@8V%L;#H@)61<;B(L
M($=E=$QA<W1%<G)O<***@I*3L-"@D)<F5T=7)N.PT*(" @('T-"@T*"2\O+R!C
5;&]S92!H86YD;&5R<R!H97)E#0I]
`
end
satishsuman
2008-04-17 10:16:01 UTC
Permalink
I am new in forum..
And i m not able to see(find) ur attached source code..

How to get it?
Post by Volodymyr M. Shcherbyna
Attached is the source code.
--
V.
This posting is provided "AS IS" with no warranties, and confers no
rights.
Post by Volodymyr M. Shcherbyna
[...]
Post by satishsuman
HttpOpenRequest works an return message is Ya! Success! Error = 122
First, you have to understand, that if the function returns TRUE, there is
no need to look at error code - it does not have meaning.
Post by satishsuman
HttpSendRequestEx goes in else and gives message No! Failure! Error = 87.
I bet you got errors just because LPINTERNET_BUFFERS lpBuffersOut for
HttpSendRequestEx is reserved, and should be NULL. Also, you do not pass
correct url into InternetConnect. It should be withOUT http://.
I will attach a complete working source code in next message. You will be
able to download the source code if you use Outlook Express.
--
V.
This posting is provided "AS IS" with no warranties, and confers no
rights.
Post by satishsuman
I am trying to make a HTTP connection with web server and trying to pass
authentication information.
I included INet.h.
My code for http request is..
***************************************************************************************
HINTERNET hSession = ::InternetOpen("SomeName",
PRE_CONFIG_INTERNET_ACCESS,
NULL,
INTERNET_INVALID_PORT_NUMBER,
0) ;
HINTERNET hConnect = ::InternetConnect(hSession,
"http://localhost/login",
INTERNET_DEFAULT_HTTP_PORT,
user_id,
password,
INTERNET_SERVICE_HTTP,
0,
0) ;
SetLastError(0);
HINTERNET hHttpFile = ::HttpOpenRequest(hConnect,
"POST",
"",
HTTP_VERSION,
NULL,
0,
INTERNET_FLAG_DONT_CACHE,
0);
if(hHttpFile)
{
DWORD dwErr = GetLastError();
char message[1000];
sprintf(message, "Ya! Success! - Error = %u", dwErr);
MessageBox(NULL, message, "HttpOpenRequest", MB_OK);
}
else
{
DWORD dwErr = GetLastError();
char message[1000];
sprintf(message, "No! Failure! - Error = %u", dwErr);
MessageBox(NULL, message, "HttpOpenRequest", MB_OK);
}
INTERNET_BUFFERS inBuf;
inBuf.dwStructSize = sizeof(INTERNET_BUFFERS);
inBuf.Next = NULL;
inBuf.lpcszHeader = NULL;
inBuf.dwHeadersLength = 0;
inBuf.dwHeadersTotal = 0;
char postData[1000];
sprintf(postData, "user_id=%s&password=%s", user_id, password);
inBuf.lpvBuffer = postData;
inBuf.dwBufferLength = strlen(postData);
inBuf.dwBufferTotal = strlen(postData);
inBuf.dwOffsetLow = 0;
inBuf.dwOffsetHigh = 0;
INTERNET_BUFFERS outBuf;
outBuf.dwStructSize = sizeof(INTERNET_BUFFERS);
outBuf.Next = NULL;
outBuf.lpcszHeader = NULL;
outBuf.dwHeadersLength = 0;
outBuf.dwHeadersTotal = 0;
outBuf.lpvBuffer = new char[1000];
outBuf.dwBufferLength = 1000;
outBuf.dwBufferTotal = 1000;
outBuf.dwOffsetLow = 0;
outBuf.dwOffsetHigh = 0;
SetLastError(0);
BOOL bSendRequest = ::HttpSendRequestEx(hHttpFile, &inBuf, &outBuf,
HSR_SYNC, NULL);
if(bSendRequest)
{
DWORD dwErr = GetLastError();
char message[1000];
sprintf(message, "Ya! Success! - Error = %u", dwErr);
MessageBox(NULL, message, "HttpSendRequest", MB_OK);
}
else
{
DWORD dwErr = GetLastError();
char message[1000];
sprintf(message, "No! Failure! - Error = %u", dwErr);
MessageBox(NULL, message, "HttpSendRequest", MB_OK);
}
*****************************************************************************************************************
HttpOpenRequest works an return message is Ya! Success! Error = 122
HttpSendRequestEx goes in else and gives message No! Failure! Error = 87.
What is wrong with my code?
Volodymyr M. Shcherbyna
2008-04-17 13:41:48 UTC
Permalink
Probably you're accessing the newsgroup from google.com. I suggest you to
use Outlook Express (OE) and configure it to use msnews.microsoft.com NG
server. Then, find newsgroup microsoft.public.inetsdk.programming.wininet.
You will be able to access attachments only from OE.
--
V.
This posting is provided "AS IS" with no warranties, and confers no
rights.
Post by satishsuman
I am new in forum..
And i m not able to see(find) ur attached source code..
How to get it?
Post by Volodymyr M. Shcherbyna
Attached is the source code.
--
V.
This posting is provided "AS IS" with no warranties, and confers no
rights.
Post by Volodymyr M. Shcherbyna
[...]
Post by satishsuman
HttpOpenRequest works an return message is Ya! Success! Error = 122
First, you have to understand, that if the function returns TRUE, there is
no need to look at error code - it does not have meaning.
Post by satishsuman
HttpSendRequestEx goes in else and gives message No! Failure! Error = 87.
I bet you got errors just because LPINTERNET_BUFFERS lpBuffersOut for
HttpSendRequestEx is reserved, and should be NULL. Also, you do not pass
correct url into InternetConnect. It should be withOUT http://.
I will attach a complete working source code in next message. You will be
able to download the source code if you use Outlook Express.
--
V.
This posting is provided "AS IS" with no warranties, and confers no
rights.
Post by satishsuman
I am trying to make a HTTP connection with web server and trying to pass
authentication information.
I included INet.h.
My code for http request is..
***************************************************************************************
HINTERNET hSession = ::InternetOpen("SomeName",
PRE_CONFIG_INTERNET_ACCESS,
NULL,
INTERNET_INVALID_PORT_NUMBER,
0) ;
HINTERNET hConnect = ::InternetConnect(hSession,
"http://localhost/login",
INTERNET_DEFAULT_HTTP_PORT,
user_id,
password,
INTERNET_SERVICE_HTTP,
0,
0) ;
SetLastError(0);
HINTERNET hHttpFile = ::HttpOpenRequest(hConnect,
"POST",
"",
HTTP_VERSION,
NULL,
0,
INTERNET_FLAG_DONT_CACHE,
0);
if(hHttpFile)
{
DWORD dwErr = GetLastError();
char message[1000];
sprintf(message, "Ya! Success! - Error = %u", dwErr);
MessageBox(NULL, message, "HttpOpenRequest", MB_OK);
}
else
{
DWORD dwErr = GetLastError();
char message[1000];
sprintf(message, "No! Failure! - Error = %u", dwErr);
MessageBox(NULL, message, "HttpOpenRequest", MB_OK);
}
INTERNET_BUFFERS inBuf;
inBuf.dwStructSize = sizeof(INTERNET_BUFFERS);
inBuf.Next = NULL;
inBuf.lpcszHeader = NULL;
inBuf.dwHeadersLength = 0;
inBuf.dwHeadersTotal = 0;
char postData[1000];
sprintf(postData, "user_id=%s&password=%s", user_id, password);
inBuf.lpvBuffer = postData;
inBuf.dwBufferLength = strlen(postData);
inBuf.dwBufferTotal = strlen(postData);
inBuf.dwOffsetLow = 0;
inBuf.dwOffsetHigh = 0;
INTERNET_BUFFERS outBuf;
outBuf.dwStructSize = sizeof(INTERNET_BUFFERS);
outBuf.Next = NULL;
outBuf.lpcszHeader = NULL;
outBuf.dwHeadersLength = 0;
outBuf.dwHeadersTotal = 0;
outBuf.lpvBuffer = new char[1000];
outBuf.dwBufferLength = 1000;
outBuf.dwBufferTotal = 1000;
outBuf.dwOffsetLow = 0;
outBuf.dwOffsetHigh = 0;
SetLastError(0);
BOOL bSendRequest = ::HttpSendRequestEx(hHttpFile, &inBuf, &outBuf,
HSR_SYNC, NULL);
if(bSendRequest)
{
DWORD dwErr = GetLastError();
char message[1000];
sprintf(message, "Ya! Success! - Error = %u", dwErr);
MessageBox(NULL, message, "HttpSendRequest", MB_OK);
}
else
{
DWORD dwErr = GetLastError();
char message[1000];
sprintf(message, "No! Failure! - Error = %u", dwErr);
MessageBox(NULL, message, "HttpSendRequest", MB_OK);
}
*****************************************************************************************************************
HttpOpenRequest works an return message is Ya! Success! Error = 122
HttpSendRequestEx goes in else and gives message No! Failure! Error = 87.
What is wrong with my code?
sascg
2008-07-13 22:53:30 UTC
Permalink
I'm very interested in seeing your code. I opened this thread in OE, but
apparently
the thread has been archived. When I opened your response, there was not an
attachment available. Any chance you would repost, including the attachment?

Much appreciated,

sascg
Post by Volodymyr M. Shcherbyna
Probably you're accessing the newsgroup from google.com. I suggest you to
use Outlook Express (OE) and configure it to use msnews.microsoft.com NG
server. Then, find newsgroup microsoft.public.inetsdk.programming.wininet.
You will be able to access attachments only from OE.
--
V.
This posting is provided "AS IS" with no warranties, and confers no
rights.
Post by satishsuman
I am new in forum..
And i m not able to see(find) ur attached source code..
How to get it?
Post by Volodymyr M. Shcherbyna
Attached is the source code.
--
V.
This posting is provided "AS IS" with no warranties, and confers no
rights.
Post by Volodymyr M. Shcherbyna
[...]
Post by satishsuman
HttpOpenRequest works an return message is Ya! Success! Error = 122
First, you have to understand, that if the function returns TRUE, there is
no need to look at error code - it does not have meaning.
Post by satishsuman
HttpSendRequestEx goes in else and gives message No! Failure! Error = 87.
I bet you got errors just because LPINTERNET_BUFFERS lpBuffersOut for
HttpSendRequestEx is reserved, and should be NULL. Also, you do not pass
correct url into InternetConnect. It should be withOUT http://.
I will attach a complete working source code in next message. You will be
able to download the source code if you use Outlook Express.
--
V.
This posting is provided "AS IS" with no warranties, and confers no
rights.
Post by satishsuman
I am trying to make a HTTP connection with web server and trying to pass
authentication information.
I included INet.h.
My code for http request is..
***************************************************************************************
HINTERNET hSession = ::InternetOpen("SomeName",
PRE_CONFIG_INTERNET_ACCESS,
NULL,
INTERNET_INVALID_PORT_NUMBER,
0) ;
HINTERNET hConnect = ::InternetConnect(hSession,
"http://localhost/login",
INTERNET_DEFAULT_HTTP_PORT,
user_id,
password,
INTERNET_SERVICE_HTTP,
0,
0) ;
SetLastError(0);
HINTERNET hHttpFile = ::HttpOpenRequest(hConnect,
"POST",
"",
HTTP_VERSION,
NULL,
0,
INTERNET_FLAG_DONT_CACHE,
0);
if(hHttpFile)
{
DWORD dwErr = GetLastError();
char message[1000];
sprintf(message, "Ya! Success! - Error = %u", dwErr);
MessageBox(NULL, message, "HttpOpenRequest", MB_OK);
}
else
{
DWORD dwErr = GetLastError();
char message[1000];
sprintf(message, "No! Failure! - Error = %u", dwErr);
MessageBox(NULL, message, "HttpOpenRequest", MB_OK);
}
INTERNET_BUFFERS inBuf;
inBuf.dwStructSize = sizeof(INTERNET_BUFFERS);
inBuf.Next = NULL;
inBuf.lpcszHeader = NULL;
inBuf.dwHeadersLength = 0;
inBuf.dwHeadersTotal = 0;
char postData[1000];
sprintf(postData, "user_id=%s&password=%s", user_id, password);
inBuf.lpvBuffer = postData;
inBuf.dwBufferLength = strlen(postData);
inBuf.dwBufferTotal = strlen(postData);
inBuf.dwOffsetLow = 0;
inBuf.dwOffsetHigh = 0;
INTERNET_BUFFERS outBuf;
outBuf.dwStructSize = sizeof(INTERNET_BUFFERS);
outBuf.Next = NULL;
outBuf.lpcszHeader = NULL;
outBuf.dwHeadersLength = 0;
outBuf.dwHeadersTotal = 0;
outBuf.lpvBuffer = new char[1000];
outBuf.dwBufferLength = 1000;
outBuf.dwBufferTotal = 1000;
outBuf.dwOffsetLow = 0;
outBuf.dwOffsetHigh = 0;
SetLastError(0);
BOOL bSendRequest = ::HttpSendRequestEx(hHttpFile, &inBuf, &outBuf,
HSR_SYNC, NULL);
if(bSendRequest)
{
DWORD dwErr = GetLastError();
char message[1000];
sprintf(message, "Ya! Success! - Error = %u", dwErr);
MessageBox(NULL, message, "HttpSendRequest", MB_OK);
}
else
{
DWORD dwErr = GetLastError();
char message[1000];
sprintf(message, "No! Failure! - Error = %u", dwErr);
MessageBox(NULL, message, "HttpSendRequest", MB_OK);
}
*****************************************************************************************************************
HttpOpenRequest works an return message is Ya! Success! Error = 122
HttpSendRequestEx goes in else and gives message No! Failure! Error = 87.
What is wrong with my code?
Volodymyr M. Shcherbyna
2008-07-14 09:29:05 UTC
Permalink
It was long time ago, I will check for the sources at my machine and will
reply here within 24 hours.
--
Volodymyr, blog: http://www.shcherbyna.com/
(This posting is provided "AS IS" with no warranties, and confers no
rights)
Post by sascg
I'm very interested in seeing your code. I opened this thread in OE, but
apparently
the thread has been archived. When I opened your response, there was not an
attachment available. Any chance you would repost, including the attachment?
Much appreciated,
sascg
Post by Volodymyr M. Shcherbyna
Probably you're accessing the newsgroup from google.com. I suggest you to
use Outlook Express (OE) and configure it to use msnews.microsoft.com NG
server. Then, find newsgroup
microsoft.public.inetsdk.programming.wininet.
You will be able to access attachments only from OE.
--
V.
This posting is provided "AS IS" with no warranties, and confers no
rights.
Post by satishsuman
I am new in forum..
And i m not able to see(find) ur attached source code..
How to get it?
Post by Volodymyr M. Shcherbyna
Attached is the source code.
--
V.
This posting is provided "AS IS" with no warranties, and confers no
rights.
Post by Volodymyr M. Shcherbyna
[...]
Post by satishsuman
HttpOpenRequest works an return message is Ya! Success! Error = 122
First, you have to understand, that if the function returns TRUE,
there
is
no need to look at error code - it does not have meaning.
Post by satishsuman
HttpSendRequestEx goes in else and gives message No! Failure! Error
=
87.
I bet you got errors just because LPINTERNET_BUFFERS lpBuffersOut
for
HttpSendRequestEx is reserved, and should be NULL. Also, you do not pass
correct url into InternetConnect. It should be withOUT http://.
I will attach a complete working source code in next message. You
will
be
able to download the source code if you use Outlook Express.
--
V.
This posting is provided "AS IS" with no warranties, and confers no
rights.
Post by satishsuman
I am trying to make a HTTP connection with web server and trying to pass
authentication information.
I included INet.h.
My code for http request is..
***************************************************************************************
HINTERNET hSession = ::InternetOpen("SomeName",
PRE_CONFIG_INTERNET_ACCESS,
NULL,
INTERNET_INVALID_PORT_NUMBER,
0) ;
HINTERNET hConnect = ::InternetConnect(hSession,
"http://localhost/login",
INTERNET_DEFAULT_HTTP_PORT,
user_id,
password,
INTERNET_SERVICE_HTTP,
0,
0) ;
SetLastError(0);
HINTERNET hHttpFile = ::HttpOpenRequest(hConnect,
"POST",
"",
HTTP_VERSION,
NULL,
0,
INTERNET_FLAG_DONT_CACHE,
0);
if(hHttpFile)
{
DWORD dwErr = GetLastError();
char message[1000];
sprintf(message, "Ya! Success! - Error = %u", dwErr);
MessageBox(NULL, message, "HttpOpenRequest", MB_OK);
}
else
{
DWORD dwErr = GetLastError();
char message[1000];
sprintf(message, "No! Failure! - Error = %u", dwErr);
MessageBox(NULL, message, "HttpOpenRequest", MB_OK);
}
INTERNET_BUFFERS inBuf;
inBuf.dwStructSize = sizeof(INTERNET_BUFFERS);
inBuf.Next = NULL;
inBuf.lpcszHeader = NULL;
inBuf.dwHeadersLength = 0;
inBuf.dwHeadersTotal = 0;
char postData[1000];
sprintf(postData, "user_id=%s&password=%s", user_id, password);
inBuf.lpvBuffer = postData;
inBuf.dwBufferLength = strlen(postData);
inBuf.dwBufferTotal = strlen(postData);
inBuf.dwOffsetLow = 0;
inBuf.dwOffsetHigh = 0;
INTERNET_BUFFERS outBuf;
outBuf.dwStructSize = sizeof(INTERNET_BUFFERS);
outBuf.Next = NULL;
outBuf.lpcszHeader = NULL;
outBuf.dwHeadersLength = 0;
outBuf.dwHeadersTotal = 0;
outBuf.lpvBuffer = new char[1000];
outBuf.dwBufferLength = 1000;
outBuf.dwBufferTotal = 1000;
outBuf.dwOffsetLow = 0;
outBuf.dwOffsetHigh = 0;
SetLastError(0);
BOOL bSendRequest = ::HttpSendRequestEx(hHttpFile, &inBuf, &outBuf,
HSR_SYNC, NULL);
if(bSendRequest)
{
DWORD dwErr = GetLastError();
char message[1000];
sprintf(message, "Ya! Success! - Error = %u", dwErr);
MessageBox(NULL, message, "HttpSendRequest", MB_OK);
}
else
{
DWORD dwErr = GetLastError();
char message[1000];
sprintf(message, "No! Failure! - Error = %u", dwErr);
MessageBox(NULL, message, "HttpSendRequest", MB_OK);
}
*****************************************************************************************************************
HttpOpenRequest works an return message is Ya! Success! Error = 122
HttpSendRequestEx goes in else and gives message No! Failure! Error
=
87.
What is wrong with my code?
Loading...