TClientSocketを介して Web サイトから画像を読み込もうとしています。私はTClinetSocketでそれを行うことはなく、INDYなどの他のコンポーネントは使用しません。
SckServer.Close;
SckServer.port:=80;
SckServer.Address:='127.0.0.1';
SckServer.Open;
procedure TForm1.Button3Click(Sender: TObject);
begin
img_url:='/img/logo.png';
SckServer.Socket.SendText(
'GET '+img_url+' HTTP/1.1' + #13#10 +
'Host: localhost.com' + #13#10 +
'User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.2.1) Gecko/20021204' + #13#10 +
'Accept: text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,video/x-mng,image/png,image/jpeg,image/gif;q=0.2,text/css,*/*;q=0.1' + #13#10 +
'Accept-Language: en-us, en;q=0.50' + #13#10 +
'Accept-Encoding: gzip, deflate, compress;q=0.9' + #13#10 +
'Accept-Charset: ISO-8859-1, utf-8;q=0.66, *;q=0.66' + #13#10 +
'Keep-Alive: 300' + #13#10 +
'Connection: keep-alive' + #13#10 +
'Cache-Control: max-age=0' +#13#10 +
'Referer: http://localhost.com'+ #13#10 +
#13#10
);
end;
procedure TForm1.SckServerRead(Sender: TObject; Socket: TCustomWinSocket);
begin
form1.caption:='Ready';
s:= s+SckServer.Socket.ReceiveText;
s:=StringReplace(s, #10, '', [rfReplaceAll]);
s:=StringReplace(s, #13, '', [rfReplaceAll]);
s:=StringReplace(s, '¶', '', [rfReplaceAll]);
memo1.Lines.Add(s);
end;
応答テキストは
HTTP/1.1 200 OK
サーバー: nginx/1.8.1
日付: 2016 年 3 月 11 日金曜日 16:53:29 GMT
Content-Type: image/png
Content-Length: 1248
接続: キープアライブ
P3P: CP="NOI DEVa TAIa OUR BUS UNI STA"
Last-Modified: Fri, 11 Mar 2016 16:53:29 GMT
Expires: Fri, 11 Mar 2016 16:53:29 GMT
Cache-Control: private, no-cache, no-store, must-revalidate , max-age=0
プラグマ: no-cache
‰PNG
そして、私は応答に画像が表示されません