Delphi HTTP Post JSON

前端 未结 2 1727
闹比i
闹比i 2021-01-02 06:47

I am sure I\'m doing something wrong here. I\'ve followed every example I can find on stackoverflow and still haven\'t gotten this to work in my environment. I\'d love to up

2条回答
  •  渐次进展
    2021-01-02 07:37

    Please try this:

    procedure TForm1.Button1Click(Sender: TObject);
        var
            s: String;
            Resp_Json: string;
            Req_Json:TStream;
    begin
        s:='state=1';
        s:=s+'&kind=0';
        s:=s+'&tblid=0';
        Req_Json:=TstringStream.Create(s);
        Req_Json.Position:=0;
    
        try
            IdHTTP1.Request.UserAgent:='Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/61.0.3163.100 Safari/537.36';
            IdHTTP1.Request.Accept := 'application/json, text/javascript, */*; q=0.01';
            IdHTTP1.Request.ContentType := 'application/x-www-form-urlencoded; charset=UTF-8';
            IdHTTP1.Request.CharSet:='utf-8';
            Resp_Json:=IdHTTP1.Post('http://[your URL]', Req_Json);
        finally
            Req_Json.Free;
        end;
    
        memo1.Lines.Add(IdHTTP1.ResponseText);
        memo1.Lines.Add(Resp_Json);
    end;
    

提交回复
热议问题