各位大最近研究WEBQQ,心跳包哪里POST回傳的資料超過255位元組就收不到任何的資料,回傳空值,研究了半天不知道為什么,有沒有知道的各位大大幫忙下,100分送上
下面是代碼:
function TCommunication.WebQQPoll2(var Str:TStringStream):string ;
var
Response,PostData: TStringStream;
begin
CoInitialize(nil);// 初始化 COM 庫
IdHTTP:=TIdHTTP.Create(nil);
IdCookieManager:=TIdCookieManager.Create(nil);
IdSSLIOHandlerSocketOpenSSL:=TIdSSLIOHandlerSocketOpenSSL.Create(nil);
Response:=TStringStream.Create('',TEncoding.GetEncoding(65001)) ;
//Response.Size:=99999;
PostData:=TStringStream.Create('r=%7B%22clientid%22%3A%22'+WebQQClientid+'%22%2C%22psessionid%22%3A%22'+psessionid+'%22%2C%22key%22%3A0%2C%22ids%22%3A%5B%5D%7D&clientid='+WebQQClientid+'&psessionid='+psessionid) ;
try
Result:='' ;
IdHTTP.AllowCookies:=False ;
IdHTTP.HandleRedirects:=True ;
IdHTTP.CookieManager:=IdCookieManager ;
IdHTTP.IOHandler:=IdSSLIOHandlerSocketOpenSSL ;
IdCookieManager.OnNewCookie:=IdCookieManagerNewCookie ;
IdHTTP.HTTPOptions:=[hoInProcessAuth,hoKeepOrigProtocol,hoForceEncodeParams] ;
IdHTTP.ProtocolVersion:=pv1_1 ;
IdHTTP.Request.Accept:='*/*';
IdHTTP.Request.AcceptEncoding:='gzip, deflate';
IdHTTP.Request.AcceptLanguage:='zh-CN';
IdHTTP.Request.CacheControl:='no-cache';
IdHTTP.Request.Connection:='Keep-Alive';
IdHTTP.Request.ContentType:='application/x-www-form-urlencoded';
IdHTTP.Request.Host:='d.web2.qq.com';
IdHTTP.Request.Referer:='http://d.web2.qq.com/proxy.html?v=20110331002&callback=1&id=2';
IdHTTP.Request.UserAgent:='Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; Trident/5.0)';
IdHTTP.Request.CustomHeaders.Text:='Cookie:'+Cookies ;
IdHTTP.Post('http://d.web2.qq.com/channel/poll2',PostData,Response) ;
//Response.SaveToFile('c:\1234.txt');
if Trim(Response.DataString)='' then
begin
Exit ;
end;
Str.Clear ;
Str.Position:=0;
Str.LoadFromStream(Response);
Result:=ReadJson(Trim(Response.DataString),'retcode') ;
finally
Response.Free ;
PostData.Free ;
IdCookieManager.Free ;
IdSSLIOHandlerSocketOpenSSL.Free ;
IdHTTP.Free ;
CoUninitialize();
end;
end;
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/110205.html
標籤:網絡通信/分布式開發
