#1 2015-05-20 15:39:26

jars
Member
Registered: 2015-05-15
Posts: 29

How make Post to a Web Services that response with http code and Json

Hi, guys.
I´m developing with Delphi 7 and need to connect to a web services and make an http post with some parameters.
Can showme some example of use?
Thanks in advance

Offline

#2 2015-05-20 19:38:57

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,655
Website

Re: How make Post to a Web Services that response with http code and Json

Which Web Service?

For simple REST client using some of our units, see http://stackoverflow.com/a/22078557/458259

Offline

#3 2015-05-21 14:24:12

jars
Member
Registered: 2015-05-15
Posts: 29

Re: How make Post to a Web Services that response with http code and Json

Thanks for the example, this is what I need.
This post has a response with a json object, how can I get this response?
Sorry I'd never worked with web services.

Offline

#4 2015-05-21 14:29:34

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,655
Website

Re: How make Post to a Web Services that response with http code and Json

TWinHttp.Post() returns a string.
Just pass it into a TDocVariant:

uses SynCrtSock, SynCommons;
var t,resp: variant;
begin
  TDocVariant.New(t);
  t.name := 'john';
  t.year := 1982;
  resp := _JsonFast(TWinHTTP.Post('http://servername/resourcename',t,'Content-Type: application/json'));
  if resp.firstname='John' then
    ....
end;

Offline

#5 2015-05-21 14:35:32

jars
Member
Registered: 2015-05-15
Posts: 29

Re: How make Post to a Web Services that response with http code and Json

Many thanks for your kuicly response, it´s all i need for now.

Offline

#6 2015-05-25 14:26:21

edwinsn
Member
Registered: 2010-07-02
Posts: 1,218

Re: How make Post to a Web Services that response with http code and Json

Hi Arnaud,

Looks like TWinHTTP includes all functionalities needed to implement a generic REST client?


Delphi XE4 Pro on Windows 7 64bit.
Lazarus trunk built with fpcupdelux on Windows with cross-compile for Linux 64bit.

Offline

#7 2015-05-25 14:47:40

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,655
Website

Re: How make Post to a Web Services that response with http code and Json

Yes, it is a brand full HTTP client access.

If you add TDocVariant/TDocVariantData for JSON support, you should have all you need.

Offline

#8 2015-05-25 19:59:34

Junior/RO
Member
Registered: 2011-05-13
Posts: 210

Re: How make Post to a Web Services that response with http code and Json

What if I post a flac audio file (or stream) for the google Speech Api? TDocVarient will handle this?

Offline

#9 2015-05-26 05:09:21

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,655
Website

Re: How make Post to a Web Services that response with http code and Json

No here you use RawByteString, with the proper mime type specified in the HTTP headers.

TDocVariant is for json content.

Offline

Board footer

Powered by FluxBB