0

我尝试了以下 HTTP GET 请求

function CreateHTTPRequest(Site: String): String;
var
    Request: String;
begin
    Randomize;
    Request := 'GET ' + Site + ' HTTP/1.1' + #13#10;
    Request := Request + 'Host: ' + Site + #13#10;
    Request := Request + 'Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8' + #13#10;
    Request := Request + 'Accept-Language: en-us,en' + #13#10;
    Request := Request + 'User-Agent: ' + UserAgent + #13#10;
    Request := Request + 'Referer: ' + Referer + #13#10;
    Request := Request + 'Connection: close' + #13#10#13#10;
    Result := Request;
end;

var
    httpSocket: TClientSocket;
    Site: String;
    Target : string;
begin
    httpSocket := TClientSocket.Create(nil);
    httpSocket.Host := 'www.google.com';
    httpSocket.Port := 80;
    httpSocket.ClientType := ctBlocking;
    httpSocket.Active := True;
    if httpSocket.Socket.Connected=True then
    begin
        memo1.Lines.Add('requested');
        Site := 'http://' + 'google.com';
        httpSocket.Socket.SendText(CreateHTTPRequest(Site));
        memo1.Lines.Add(httpSocket.Socket.ReceiveText);
        httpSocket.Active := False;
    end;

    httpSocket.Free;
end;

我没有得到任何回应。我做错了什么?我不能用 TclientSocket 做更多的 HTTPS 请求。是不是已经死了?

4

0 回答 0