Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

HTTP Client using MFC... 1

Status
Not open for further replies.

madhosh

Programmer
Aug 10, 2001
14
Hi Guys...
Need some help here.. I have been trying to acess web pages using C++ (MFC) . I have used following piece of code

CInternetSession init;
CHttpConnection* conn;
CHttpFile* file;
conn=init.GetHttpConnection( pstrServer, nPort,
pstrUserName, pstrPassword );

file=conn->OpenRequest(pstrVerb, pstrObjectName, pstrReferer , dwContext , pstrAcceptTypes , pstrVersion ,dwFlags);

file->SendRequest( pstrHeaders , dwHeadersLen , lpOptional , dwOptionalLen );

file->SetReadBufferSize(10000);

file->ReadString(str );

pstr=str.GetBuffer(10000);

but something seems to go wrong at ReadString Stage. I get following output no matter what website address i give

<!DOCTYPE HTML PUBLIC &quot;-//W3C//DTD HTML 3.2 Final//EN&quot;>

Can anyone help?? The verb iam using is &quot;POST&quot;.
 
That's what I would expect because ReadString() reads until it detects the first &quot;newline&quot;. Try to call ReadString() multiple times until the return value is FALSE.
 
Thanks a lot rpet.. That was dumb of me not to see such a simple thing..

Guys One more help. When i try to access a web page using above code. It gives me &quot;Proxy Authentication failed &quot; error. My user name and Password are correct.. Any idea where i can set up user name and password . ( right now iam passing it in
GetHttpConnection( pstrServer, nPort,pstrUserName, pstrPassword );

Any help will be appreciated.
 
That depends on how the proxy autentication is set up. Usually it uses Kerberos for that. Anyway you can get HTTP error 407 Proxy authentication failed also for not supplying a &quot;valid&quot; value for the User-Agent header line(User-Agent from HTTP, you can find something also in ASP.)

I think this is a starting point for you.

HTH, s-)

Blessed is he who in the name of justice and goodwill, sheperds the weak through the valley of darkness...
 
Again Thanks ... Iam really stuck.. Now I get this error..
Iam doing this for the first time.. so please bear up with me guys,, Any help will be appreciated...


HTTP_STATUS_DENIED 401 The requested resource requires user authentication.
 
HTTP_STATUS_DENIED 401 The requested resource requires user authentication. - means that you should use a authentication method to access the resource(the file that is requested from the server by your client aplication).

I supose that your file(resource) is protected on the server by an autentication method(Basic, Negotiate, NTLM). If you are supplying corect values for PWD and USERNAME and still get this answer then:
- the authentication method is wrong(Don't know very well the CInternetSession class but try to find some option method)
- the file has a different password and username than others. Some server allow for different PWD and USERNAME on each file.

HTH, s-)

Blessed is he who in the name of justice and goodwill, sheperds the weak through the valley of darkness...
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top