1

EDIT: I need to make a POST connection with TTCPBlocksocket inside a delphi based applications script engine.

How to tell synapse where Header ends and body (post elements) starts? Or should i send them in different packets? Thank you !

begin
  Head:= TStringList.Create;
  Head.Add('GET / HTTP/1.1');           
  Head.Add('Accept: */*');
  Head.Add('Accept-Encoding: gzip, deflate');
  Head.Add('Host: www.google.ru');
  Head.Add('Connection: Keep-Alive');
  Head.Add(#10#13);

    body:= TStringList.Create;
  body.Add('username=adr');
  body.Add('login=adr');
  body.Add('password=adr');
  body.Add('r_password=adr');
  body.Add('submit=register');


  Socket:= TTCPBlockSocket.Create;      
  Socket.connect('108.167.137.28', '80'); 
  if (Socket.LastError <> 0) then Exit;   
  Socket.SendString(Head.Text);    
  • Thank you david, i have edited the post , hope it's easier to understand now. – Tomas Randomas Sep 12 '16 at 14:22
  • I'v read the mcve guide, unfortunately i cannot share the program that is needed to reproduce the error itself since it's not free. The peace of code i have posted is just to get an idea of what i'm trying to accomplish , and i think that my main questions are pretty clear , its basicly just how to form a http post packet , thank you for assistance! – Tomas Randomas Sep 12 '16 at 14:43
  • First, your example above is wrong. A `GET` request cannot have a body, you need `POST` instead. Second, Synapse has a [`THTTPSend`](http://synapse.ararat.cz/doc/help/httpsend.html) class, you should be using that for HTTP requests. Don't use `TTCPBlockSocket` directly to implement HTTP manually. In your example above, you would sent your `name=value` pairs using the `THTTPSend.HttpPostURL()` method. – Remy Lebeau Sep 12 '16 at 21:51

1 Answers1

1

Solved by this topic - How are parameters sent in an HTTP POST request?

The content is put after the HTTP headers. The format of an HTTP POST is to have the HTTP headers, followed by a blank line, followed by the request body. The POST variables are stored as key-value pairs in the body.

Community
  • 1
  • 1