老有关问题没解决,新有关问题又来了,还是idhttp
老问题没解决,新问题又来了,还是idhttp
http://www.118100.cn/action/secweborder/isCTMobile.do?mobile=13325152233
delphi2010 这个本来就返回一个1字符串,但是怎么转都是乱码。
但是用delphi 6的 idhttp.get回来的就能正确显示
求高人给个完整的代码,这两天为这事头疼死了。
------解决方案--------------------
你怎么就断定是代码转换的问题呢? 在GET前面加下面一行试试看。
IdHTTP1.Request.UserAgent:='Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1)';
------解决方案--------------------
不是这些问题,是因为返回的内容压缩了,返回实际内容如下:
/**********************************************
HTTP/1.1 200 OK
Date: Thu, 06 Sep 2012 11:27:19 GMT
Content-Type: text/html;charset=UTF-8
Transfer-Encoding: chunked
Connection: keep-alive
Vary: Accept-Encoding
Set-Cookie: JSESSIONID=03CDFB6D0A3F939F665E8C1CAA999103; Path=/
Server: N.WEBPROXY-1.20
Expires: Thu, 06 Sep 2012 11:27:19 GMT
Cache-Control: max-age=0
Content-Encoding: gzip
15
?
***************************/
要自己用gzip解压缩
------解决方案--------------------
procedure DecompressGZip(AInStream, AOutStream: TStream);
procedure TDemoForm.DecompressGZip(AInStream, AOutStream: TStream);
var
pb1, pb2: Byte;
begin
AInStream.Seek(1, 0);
AInStream.Read(pb1, 1);
AInStream.Seek(2, 0);
AInStream.Read(pb2, 1);
AInStream.Position := 0;
AOutStream.Position := 0;
if (pb1 = $8B) and (pb2 = $8) then //gzip
ZDecompressStream2(AInStream, AOutStream, 47)
else
AOutStream.CopyFrom(AInStream, AInStream.Size);
end;
自己去下个ZLibEx单元,里边有ZDecompressStream2函数
http://www.118100.cn/action/secweborder/isCTMobile.do?mobile=13325152233
delphi2010 这个本来就返回一个1字符串,但是怎么转都是乱码。
- Delphi(Pascal) code
procedure TForm1.Button6Click(Sender: TObject); var ResponseStream:TStringStream; begin ResponseStream:=TStringstream.Create('',936); IdHTTP1.Get('http://www.118100.cn/action/secweborder/isCTMobile.do?mobile=' + edit1.Text,ResponseStream); //这是UTF-8网页 memo1.Lines.Add(UTF8Decode(ResponseStream.DataString)); Freeandnil(ResponseStream); end;
但是用delphi 6的 idhttp.get回来的就能正确显示
求高人给个完整的代码,这两天为这事头疼死了。
------解决方案--------------------
你怎么就断定是代码转换的问题呢? 在GET前面加下面一行试试看。
IdHTTP1.Request.UserAgent:='Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1)';
------解决方案--------------------
不是这些问题,是因为返回的内容压缩了,返回实际内容如下:
/**********************************************
HTTP/1.1 200 OK
Date: Thu, 06 Sep 2012 11:27:19 GMT
Content-Type: text/html;charset=UTF-8
Transfer-Encoding: chunked
Connection: keep-alive
Vary: Accept-Encoding
Set-Cookie: JSESSIONID=03CDFB6D0A3F939F665E8C1CAA999103; Path=/
Server: N.WEBPROXY-1.20
Expires: Thu, 06 Sep 2012 11:27:19 GMT
Cache-Control: max-age=0
Content-Encoding: gzip
15
?
***************************/
要自己用gzip解压缩
------解决方案--------------------
procedure DecompressGZip(AInStream, AOutStream: TStream);
procedure TDemoForm.DecompressGZip(AInStream, AOutStream: TStream);
var
pb1, pb2: Byte;
begin
AInStream.Seek(1, 0);
AInStream.Read(pb1, 1);
AInStream.Seek(2, 0);
AInStream.Read(pb2, 1);
AInStream.Position := 0;
AOutStream.Position := 0;
if (pb1 = $8B) and (pb2 = $8) then //gzip
ZDecompressStream2(AInStream, AOutStream, 47)
else
AOutStream.CopyFrom(AInStream, AInStream.Size);
end;
自己去下个ZLibEx单元,里边有ZDecompressStream2函数