unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, ComCtrls, IdBaseComponent, IdComponent, IdTCPConnection,
IdTCPClient, IdHTTP, StdCtrls,msxml;
type
TForm1 = class(TForm)
IdHTTP1: TIdHTTP;
Memo1: TMemo;
procedure FormCreate(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
HttpReq: IXMLHttpRequest;
end;
var
Form1: TForm1;
implementation
uses DateUtils,superobject;
{$R *.dfm}
procedure TForm1.FormCreate(Sender: TObject);
var
url: string;
vJson: ISuperObject;
begin
HttpReq := CoXMLHTTPRequest.Create;
url := 'http://m.weather.com.cn/data/101270401.html';
HttpReq.open('Get', Url, False, EmptyParam, EmptyParam);
HttpReq.send(EmptyParam);//開始搜索
Url := HttpReq.responseText;
vjson:=so(url);
Memo1.Lines.Clear;
if vJson['weatherinfo'].AsString<>'' then
begin
vjson:=so(vJson['weatherinfo'].AsString);
memo1.Lines.Add('城市:'+vJson['city'].AsString );
Memo1.Lines.Add('今日天氣('+vJson['date_y'].AsString+' '+vjson['week'].asstring+'):');
Memo1.Lines.Add(' 溫度:'+vjson['temp1'].asstring);
Memo1.Lines.Add(' 天氣:'+vjson['weather1'].asstring);
Memo1.Lines.Add(' 風力:'+vjson['wind1'].asstring);
Memo1.Lines.Add('明日天氣('+FormatDateTime('YYYY年MM月DD日 ',DateUtils.IncDay(now))+'):');
Memo1.Lines.Add(' 溫度:'+vjson['temp2'].asstring);
Memo1.Lines.Add(' 天氣:'+vjson['weather2'].asstring);
Memo1.Lines.Add(' 風力:'+vjson['wind2'].asstring);
Memo1.Lines.Add(FormatDateTime('YYYY年MM月DD日 ',DateUtils.IncDay(now,2))+':');
Memo1.Lines.Add(' 溫度:'+vjson['temp3'].asstring);
Memo1.Lines.Add(' 天氣:'+vjson['weather3'].asstring);
Memo1.Lines.Add(' 風力:'+vjson['wind3'].asstring);
Memo1.Lines.Add(FormatDateTime('YYYY年MM月DD日 ',DateUtils.IncDay(now,3))+':');
Memo1.Lines.Add(' 溫度:'+vjson['temp4'].asstring);
Memo1.Lines.Add(' 天氣:'+vjson['weather4'].asstring);
Memo1.Lines.Add(' 風力:'+vjson['wind4'].asstring);
Memo1.Lines.Add(FormatDateTime('YYYY年MM月DD日 ',DateUtils.IncDay(now,4))+':');
Memo1.Lines.Add(' 溫度:'+vjson['temp5'].asstring);
Memo1.Lines.Add(' 天氣:'+vjson['weather5'].asstring);
Memo1.Lines.Add(' 風力:'+vjson['wind5'].asstring);
end;
end;
end.
uj5u.com熱心網友回復:
用indy取資料吧,HttpReq發送的報文頭部加了一個值為0的Content-Length,導致取不到資料。而這個Content-Length又刪不掉,所以還是用indy吧!
uj5u.com熱心網友回復:
使用TIdHTTP取資料,沒問題。
uj5u.com熱心網友回復:
這個問題有什么問題?uj5u.com熱心網友回復:
[yabao=][/yabao]
uj5u.com熱心網友回復:
技術分享貼?轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/72888.html
標籤:非技術區
上一篇:教你使用BitMoken交易所
下一篇:報表設計工具
