PDA

View Full Version : problems in QHttp post method!



Longe.W
6th April 2009, 12:45
hi!
I just want make a http login client ,
but i got some problems.

the server response a status-code 500 after the client request


QHttp *http = new QHttp("login.xxxx.xxx.xx");
QByteArray username("wbl9115");
QByteArray password("19881010");
QByteArray *data = new QByteArray("username="+username+"&password="+password+"&if_login=Y&B2=%B5%C7%C2%BC%28Login%29");
http->request(buildHeader(),*data);

buildHeader()


QHttpRequestHeader& buildHeader()
{
//constructe header
header.addValue("Accept","image/gif, image/jpeg, image/pjpeg, application/x-ms-application, application/vnd.ms-xpsdocument,"
" application/xaml+xml, application/x-ms-xbap, application/x-shockwave-flash, application/QVOD, */*");
header.addValue("Referer","http://login.xxxx.xxx.xx/index.jsp");
header.addValue("Accept-Language","zh-cn");
header.addValue("ContentType" ,"application/x-www-form-urlencoded");
header.addValue("Accept-Encoding","gzip, deflate");
header.addValue("UserAgent","Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.0; Trident/4.0; SLCC1; .NET CLR 2.0.50727;"
" Media Center PC 5.0; .NET CLR 3.5.30729; .NET CLR 3.0.30618; CIBA)");


header.addValue("Host", "login.xxxx.xxx.xx");
header.addValue("Connection", "Keep-Alive");
header.addValue("Cache-Control", "no-cache");


return header;
}


any ideas?
thax !!

wysota
6th April 2009, 14:58
Ok, but what is the request method? Looks like you didn't set it. And are you sure you want to send all those useless headers with the request? I.e. I don't think you want the answer to be deflated :)

talk2amulya
6th April 2009, 19:25
Ok, but what is the request method?

it appears that he used post() method for request as mentioned in his post.


the server response a status-code 500 after the client request

status code 500 means something is wrong with the server, not with the client

wysota
6th April 2009, 20:10
it appears that he used post() method for request as mentioned in his post.
No. He wanted to use post, but he forgot to set it in the request.




status code 500 means something is wrong with the server, not with the client

Not necessarily. A bad (malformed?) request can cause a 5xx error. It means the server encountered an error but it doesn't mean the error wasn't caused by the client.

Look that in his request there is no path and no method set for the request. Or at least not in the snippet he pasted. We don't know what was in the header originally but for sure with each request there will be more garbage there as he is operating on a non-const reference to the same object.

Longe.W
7th April 2009, 04:52
Of course the header is defined
QHttpRequestHeader header("POST","/login/login1.jsp"); I just did't give this code , sorry!
the server is work fine and the login succeed using web browser!!

wysota
7th April 2009, 08:55
Ok, first return a copy of the request not a reference to it. Second, print the created header to string, dump it to screen and compare to data actually sent by the browser. Then do the same with the request contents.

Longe.W
8th April 2009, 05:21
thank you!