Forum > Networking and Web Programming

Ararat Synapse http post in delphi

(1/1)

Woodyka:
Dears!

I would like to solve the my problem which is the following:

I have an url: http://example.net/x.html - I have to post there a variable=value - and the answer is an jpeg image, depending on the value. I works correctly with wget, but I would like to use the synapse http units, but I tried, and read about it, but I think my knowledge is too little for it.

But I can downloaded it the image without post:
  HTTP := THTTPSend.Create;
  try
    HTTP.HTTPMethod('POST', 'http://example.net/x.html');
    Memo1.Lines.Assign(HTTP.Headers);
    Memo2.Lines.LoadFromStream(HTTP.Document);
    http.Document.SaveToFile('c:\file.jpg');
  finally
    HTTP.Free;
  end;

It works. Please help me about it, how can I solve it with the mentioned post.

ik:
What exactly does not work ?
Do you understand that JPEG is a binary format so you can not display it on TMemo properly ?

Woodyka:
I mean, about how to send (post) a variable (example: sw) and its value (test) to an url, and get the answer jpg into a file.

I think about httpposturl function , but I cant use it correctly.

vvzh:
I have not used it myself, but according to documentation you can call it the following way:

--- Code: ---var
  Response: TMemoryStream;
// ...
Response := TMemoryStream.Create;
try
  HttpPostURL('http://example.net/x.html', 'sw=test', Response);
  Response.SaveToFile('c:\file.jpg');
finally
  Response.Free;
end;

--- End code ---

Woodyka:
Cool!

Thank you very much! So simple solution, but it works as well!

Thank you!

Navigation

[0] Message Index

Go to full version