For godssake, stuck in hell right now. I want to simply post some jsontext in UTF8 using IDhttp, Delphi Berlin.

For godssake, stuck in hell right now. I want to simply post some jsontext in UTF8 using IDhttp, Delphi Berlin.

The problem is, that the request itself always uses HTTP 1.0, despite setting 1.1(using wireshark here), and is not recognized by wireshark as a propper http request. The realproblem is, that the webserver seems to receive some rubbish sometimes(usually on the second post) which results in some additional chars at the end. Sending data using other RestApplications, the server always receives the correct data.
Is something wrong with the way i use indy here?

procedure TForm1.Button1Click(Sender: TObject);
var
i: Integer;
LRequest: TStringStream;
LClient: TIdHTTP;
begin
LRequest := TStringStream.Create('', TEncoding.UTF8);
try
for i := 1 to 1000 do
begin
LClient := TIdHTTP.Create();
LRequest.Clear();
LRequest.WriteString(Format('{"port": %d}', [i]));
LClient.Request.ContentType := 'text/plain;charset=UTF-8';
LClient.Request.Method := 'POST';
LClient.ProtocolVersion := pv1_1;
LClient.Request.UserAgent := 'Mozilla/5.0 (Windows NT 10.0; WOW64; rv:52.0) Gecko/20100101 Firefox/52.0';
LClient.Request.Accept := 'text/plain';
LClient.HTTPOptions := [];
LClient.Post(CIP, LRequest);
LClient.Free;
end;
finally
LRequest.Free;
end;
end;

Comments

  1. Stefan Glienke your karma is really bad, you ended up as SPAM-Comment, which i had to allow XD

    ReplyDelete
  2. Alexander Benikowski Is that a thank you?

    ReplyDelete
  3. jeff weir it fixed the HTTP 1.0->HTTP1.1, the strange 2-3 bytes at the end of the message serverside are still there. i gave up on that for now, i'll try winhttp(used it before) to compare.

    ReplyDelete

Post a Comment