Post json with RESTRequest

Need help with RESTRequest
Is there any example of doing RESTRequest post with JSON ?

I try to use param like below, but I can't put my json array in the parameter.

 procedure TForm1.Button2Click(Sender: TObject);
var
  jo: TJSONObject;
  ja: TJSONArray;
  i: integer;
begin

  ja := TJSONArray.Create;
  jo := TJSONObject.Create;
  jo.AddPair('First_Name', Edit1.Text);
  jo.AddPair('Last_Name', Edit2.Text);

  ja.AddElement(jo);


  //RESTRequest2.Params.AddItem('jsondata', ja, TRESTRequestParameterKind.pkGETorPOST);
  RESTRequest2.Execute;

  Memo2.Lines.Text:=RestResponse2.Content;
end;


Below is my server method

function TServerMethods1.InsertRecord(Data:TJSONArray): string;
var
  i: Integer;
  total :integer;
begin

  try
    Data.Size;
    fdqryStaff.Close;
    fdqryStaff.Open;
    total:=fdqryStaff.RecordCount;


    fdqryStaff.Insert;
    fdqryStaffTrxKey.Value:=total+1;
    fdqryStaffFirst_Name.Value:=TJSONObject(Data.Get(0)).Get('First_Name').JsonValue.Value;
    fdqryStaffLast_Name.Value:=TJSONObject(Data.Get(0)).Get('Last_Name').JsonValue.Value;
    fdqryStaff.Post;

    Result := 'Success';


  except
    on E : Exception do
      Result:= E.ClassName+' error raised, with message : '+E.Message;
  end;

end;
0
Fuandi
3/5/2014 2:46:52 AM
embarcadero.delphi.firemonkey 4901 articles. 4 followers. Follow

5 Replies
5267 Views

Similar Articles

[PageSpeed] 36

Use:

RESTRequest2.Method := TRESTRequestMethod.rmPOST;

RESTRequest2.AddParameter('jsondata', ja);

You don't want to do a GET if your JSON is really big. You could also Base64 encode your JSON or if you have data like a PNG you can Base64 encode that on the client and then decode it on the server.


This covers a lot of the REST client:
http://docwiki.embarcadero.com/RADStudio/XE5/en/REST_Client_Library

Also if you have Delphi on the server side as well you might try DataSnap. It handles the JSON for you.
http://docwiki.embarcadero.com/RADStudio/XE5/en/DataSnap_Overview_and_Architecture
0
Eli
3/5/2014 4:54:43 AM
I got this error

[DCC Error] Unit1.pas(84): E2250 There is no overloaded version of 'AddParameter' that can be called with these arguments


There is no jsonarray parameter for this addparameter method, it can only accept string

http://docwiki.embarcadero.com/Libraries/XE5/en/REST.Client.TCustomRESTRequest.AddParameter
0
Fuandi
3/6/2014 1:42:22 AM
RESTRequest2.AddParameter('jsondata', ja.ToString);
0
Eli
3/6/2014 2:17:14 AM
is there a way to post json/xml instead of string ? 
If I pass it as string, then my server need to read the string and convert it into json/xml. Not a good way to do.
0
Fuandi
3/6/2014 7:17:13 AM
This may be what you want. It talks about using multipart/form-data and multipart/mixed MIME types for POST:
https://stackoverflow.com/questions/4007969/application-x-www-form-urlencoded-or-multipart-form-data

This shows you how to construct a custom POST request for use with TIdHTTP.
https://stackoverflow.com/questions/20092510/support-for-utf-8-encoded-string-in-trestclient-delphi-xe5

You can also use TRESTRequest.AddBody() to add a Stream.
http://docwiki.embarcadero.com/Libraries/XE5/en/REST.Client.TCustomRESTRequest.AddBody
0
Eli
3/6/2014 2:27:22 PM
Reply:

Similar Artilces:

[svn:parrot-pdd] r22465
Author: tewk Date: Wed Oct 24 17:11:20 2007 New Revision: 22465 Modified: trunk/docs/pdds/pdd23_exceptions.pod Changes in other areas also in this revision: Added: trunk/t/op/exceptions.t Modified: trunk/DEPRECATED.pod trunk/compilers/json/JSON/pge2pir.tg trunk/compilers/json/postalcodes.pir trunk/compilers/past-pm/POST/Grammar.tg trunk/compilers/pct/src/HLLCompiler.pir trunk/compilers/pct/src/POST/Grammar.tg trunk/compilers/pge/PGE/Exp.pir trunk/compilers/pirc/src/pirutil.c trunk/compilers/tge/TGE/Compiler.pir trunk/docs/compiler_faq.p...

Delphi
Hello guys, I'm trying to manipulate a string in JSON format returned from a web service. The string returned directly by the browser (web service) is: <?xml version="1.0" encoding="UTF-8"?> <string xmlns="http://tempuri.org/">[{"ag_tipo":"C","ag_med_serv":971,"ag_hora":700,"ag_sit":"R"},{"ag_tipo":"C","ag_med_serv":1093,"ag_hora":1000,"ag_sit":"R"},{"ag_tipo":"C","ag_med_serv":1093,"ag...

Posting and Delphi
Hi, I use Delphi 3.02 and SQLAnywhere 5.5.04 One problem I am having ( it is quite rare ), is that the BDE ( I assume ) is returning a Record/Key Deleted exception. This appears to be when a record is being appended in code, eg, query1.append; query1OrderDate.value := date; .......... query1.post; It also occures after a post and a new form is opened which is retrieving the just added record, eg, select * from orders where orderID = :orderID. I have also had this error on my standalone 95 machine when cutting up text files to a table. The program parses each file, reads the code ...

My posts not being posted?
Sorry, had to do a test - I replied to a thread twice but neither of my posts have appeared...... On 12-08-08 1:47 PM, Gordon wrote: > Sorry, had to do a test - I replied to a thread twice but neither of my > posts have appeared...... This group is moderated, so that all posts go through the mailing list and SpamAssassin. SpamAssassin gave your posts a higher than normal spam score, so it held them for moderator approval. -- Chris Ilias <http://ilias.ca> Mailing list/Newsgroup moderator On 09/08/12 04:31, Chris Ilias wrote: > This group is moderated, so t...

RAD Studio 2010 (Delphi, C++Builder, and Delphi Prism) Posted
All, The new roadmap for RAD Studio has been posted. Link: http://edn.embarcadero.com/article/39934 Enjoy, Mike Michael Rozlog wrote: > All, > > The new roadmap for RAD Studio has been posted. > > Link: http://edn.embarcadero.com/article/39934 > Thanks for the info, Mike. One thing I'm missing in the slides is the effort to bring the compiler into the C++ Standard compliance (lamda/closures, auto/decltype, etc.) I hope it's just an omission! :) Il Tue, 11 May 2010 09:01:04 -0700, Alex Bakaev <a@b.cc> ha scritto: >Than...

RAD Studio 2010 (Delphi, C++Builder, and Delphi Prism) Posted
All, The new roadmap for RAD Studio has been posted. Link: http://edn.embarcadero.com/article/39934 Enjoy, Mike "Michael Rozlog" <michael.rozlog@embarcadero.com> wrote in message news:241286@forums.embarcadero.com... > The new roadmap for RAD Studio has been posted. We have to wait all the way until Commodore to get better documentation? And until Chromium to get OTA documentation? -- Remy Lebeau (TeamB) On 10.05.2010 23:50, Michael Rozlog wrote: > All, > > The new roadmap for RAD Studio has been posted. > > Link: http://e...

Ann: FastReport FMX for Delphi XE3 (FireMonkey 2) and XE2 (FireMonkey) released
Dear friends, Visual report designer is available now on both MS Windows and MAC OS X! Full sources. We can write here full list of possibilities, but it will so long. Let see FastReport VCL and FastReport FMX comparison table: http://www.fast-report.com/en/products/comparison-fast-report-firemonkey-vcl.html And all of this - just now in your hands for business-applications for Mac. Report generator FastReport FMX is the first multiplatform solution for including Business Intelligence into software based on Embarcadero FireMonkey IDE (Delphi for MS Windows and Apple Mac OS X)...

Ann: X-platform report generator for Delphi XE3 (FireMonkey 2) and XE2 (FireMonkey) released
Dear friends, Visual report designer is available now on both MS Windows and MAC OS X! Full sources. We can write here full list of possibilities, but it will so long. Let see FastReport VCL and FastReport FMX comparison table: http://www.fast-report.com/en/products/comparison-fast-report-firemonkey-vcl.html And all of this - just now in your hands for business-applications for Mac. Report generator FastReport FMX is the first multiplatform solution for including Business Intelligence into software based on Embarcadero FireMonkey IDE (Delphi for MS Windows and Apple Mac OS X)...

post not posted by admin
i submitted a post about three hours ago and it was not posted anywhere. subject was something like "response.redirect not working." just wanted to make sure it wasn't overlooked.     i just saw it posted. thank you....

Making Firemonkey more compatible with Delphi
I have programmed in Delphi since 1995 Delphi1 I am now evaluating Delphi XE4. It boggles my mind, why embarcadero has lost the most important aspects of Delphi. Simplicity and Fast User Interface creation. I can easily see how Firemonkey can be improved to bring it in line with traditional Delphi Techniques by doing the following. 1. All Firemonkey controls need a data aware counterpart. 2. Firemonkey Styles need to be converted to TControl descendants. 3. ie. TLayout goes to TPanel ( TFMXPanel ) 4. ie. TRectangle does to TFrame TFMXFrame ) 5. LiveBindings gets placed un...

HTTP post with json parameters
Hi All Can you assist me(new to http) with this code. I dont get a response. What am I doing wrong. Sorry for the double post I put this message in the wrong group. procedure TForm1.Button1Click(Sender: TObject); var HTTPClient : TIdHTTP; Params : TStringList; UrlStr, Response : String; JsonResponse : TStringStream; begin HTTPClient := TIdHTTP.Create(nil); Params := TStringList.Create; JsonResponse := TStringStream.Create; try Params.Text := '{"TillNo":1,"OperatorCode":1234,"ReceiptType":"String"}'; U...

HTTP Post with Json parameters
Hi All Can you assist me(new to http) with this code. I dont get a response. What am I doing wrong. procedure TForm1.Button1Click(Sender: TObject); var HTTPClient : TIdHTTP; Params : TStringList; UrlStr, Response : String; JsonResponse : TStringStream; begin HTTPClient := TIdHTTP.Create(nil); Params := TStringList.Create; JsonResponse := TStringStream.Create(); try Params.Text := '{"TillNo":1,"OperatorCode":1234,"ReceiptType":"String"}'; UrlStr := EditUrl.Text + 'AirtimeRequest'; try HTTP...

returning a response in json after a post
Hi, i have a webservice which i call using jquery. When i post data the request qnd response looks like this RéponseServerASP.NET Development Server/8.0.0.0DateTue, 09 Sep 2008 21:11:42 GMTX-AspNet-Version2.0.50727Cache-Controlprivate, max-age=0Content-Typetext/xml; charset=utf-8Content-Length89ConnectionCloseRequêteHostlocalhost:4555User-AgentMozilla/5.0 (Windows; U; Windows NT 5.1; fr; rv:1.9.0.1) Gecko/2008070208 Firefox/3.0.1Acceptapplication/xml, text/xml, */*Accept-Languagefr,fr-fr;q=0.8,en-us;q=0.5,en;q=0.3Accept-Encodinggzip,deflateAccept-CharsetISO-8859-1,utf-8;q=0.7,*;q=0.7Kee...

Delphi 2010 RTTI and JSON
Hi there, Henri Gourvest (http://www.progdigy.com) posted a video on YouTube about RTTI, Serialization to JSON et method Invocation based on his SuperObject latests enhancements here : http://www.youtube.com/watch?v=G6WuIQTm7hE You will need the latest SuperObject Source from SVN to play with RTTI : https://jsontoolkit.svn.sourceforge.net/svnroot/jsontoolkit/trunk Regards, -- Pierre "Pierre Yager" <pierre.yager@crisalid.com> wrote in message news:173548@forums.codegear.com... > Hi there, > > Henri Gourvest (http://www.progdigy.com) post...

Delphi 7 x Json
Im searching for a best way(if possible) to implement a Json routine in a Delphi 7 application. Tks Le 29/10/2013 20:40, Bob Gambler a écrit : > Im searching for a best way(if possible) to implement a Json routine in a Delphi 7 application. > > Tks superobject > {quote:title=Pierre Yager wrote:}{quote} > Le 29/10/2013 20:40, Bob Gambler a écrit : > > Im searching for a best way(if possible) to implement a Json routine in a Delphi 7 application. > > > > Tks > > superobject Tks ...

I posted a Delphi job in Jobs....
Hello! Need a job? Live in D.C.? I posted a Delphi job in the Jobs forum. Thanks. -d ...

Delphi and Delphi for .Net
It seems that Delphi for .Net is slower than Delphi Win32 native applicaiton. I would like to know is it true all .Net application is slower than Win32 native applicaiton or it is Delphi for .Net only. Your information is great appreciated, Inung On 2011-06-21 18:20:17 +0100, Inung Huang said: > It seems that Delphi for .Net is slower than Delphi Win32 native applicaiton. > I would like to know is it true all .Net application is slower than > Win32 native applicaiton or it is Delphi for .Net only. If you are only running the code in the application once then, yes, yo...

Delphi XE2, OSX and FireMonkey?
1. Does anyone know if developing with FireMonkey will be the only way to develop for OSX with XE2? 2. Does anyone know if you will need to compile on a Mac for OSX, or will XE2 cross compile? I know this will all come out during the world tour, but I'm just trying to get some idea so I can start planning. 1. Yes, I think for now it will be the only way. But you can probably build a native UI for OSX by directly using the API, like you can also develop Win32 applications without using the VCL. 2. XE2 will only be available for Windows, but it will compile for other platforms. &l...

Firemonkey ios image post [Edit]
how to post Tbitmap for firemonkey ios ? that I would like to send photos taken with DSRestCommand firemonkey in ios. Edited by: emb emb on May 23, 2012 1:18 AM ...

Delphi version survey
Delphi version survey results. 466 responses.  Thanks to everyone that participated.  The following link will take you to a Google docs spreadsheet (with some basic charts) of the results. http://tinyurl.com/d7axkb6 -- Kevin Powick On Sun, 23 Dec 2012 12:03:21 -0800, Kevin Powick <nospam@spamless.com> wrote: >Delphi version survey results. > >466 responses.  Thanks to everyone that participated.  The following >link will take you to a Google docs spreadsheet (with some basic >charts) of the results. > >http://tinyurl.co...

Where would I post Delphi / Spring4D Framework questions?
I don't want to post in the wrong forum and I don't see anything that looks promising ... for a question concerning the use of Spring.Collections and Spring.Collections.Lists. Thanks. Free, | I don't want to post in the wrong forum and I don't see anything that | looks promising ... for a question concerning the use of | Spring.Collections and Spring.Collections.Lists. Try ...delphi.thirdpartytools.general -- Q 1.19.1.372 (Q's Broken Toolbar.) Free Dorfman wrote: > I don't want to post in the wrong forum and I don't see anythin...

Yet Another Delphi Virus post
I'm not a Delphi user, but given the current alarm over Delphi-related viruses I thought this might interest some here. Go to the Dr. Dobb's Journal site: http://www.ddj.com Click on the link for "Source Code". A page should open with links to source code for DDJ, C/C++ Users Journal, and Windows Developer Network. Click on the link for WDN. It should take you to this FTP site: ftp://66.77.27.238/sourcecode/wd/ Double Click 2001 Download this file: dec2001.zip It contains the files from Windows Developer Magazine for Dec 2001. Unzip the fi...

Delphi FireMonkey project / testComplete and MSAA
Hi I am actualy working on a new team project developped using FireMonkey. We want to create automated tests with TestComplete which is already used to run tests on some VCL projects. Unfortunatly, we discovered that TestComplete is not directly compatible with FireMonkey application, it only sees the windows but not the controls on it. Making some research we, found that TestComplete is able to identify controls thanks to MSAA. So we created a really short project (only one form with some controls) using the FireMonkey Accessibility Pack in order to look at TestComplete's behavio...

Delphi XE5 Firemonkey iOS7 Style (where is it?)
It says here http://www.embarcadero.com/products/rad-studio/whats-new that XE5 has "iOS 7 SDK support and style" Where is the iOS7 style? - All I can see is iOS6 style components. I can compile on iOS7 and it will bring up the keyboard in iOS 7 but none of the drag and drop components from firemonkey are iOS7 style. Am I missing something obvious? > {quote:title=David Templar wrote:}{quote} > It says here http://www.embarcadero.com/products/rad-studio/whats-new that XE5 has "iOS 7 SDK support and style" > > Where is the iOS7 style? - All I can see is...

Web resources about - Post json with RESTRequest - embarcadero.delphi.firemonkey

How to start receiving inbound email — Mailgun REST API 2.0 documentation
public static ClientResponse CreateRoute () { Client client = Client . create (); client . addFilter ( new HTTPBasicAuthFilter ( "api" , "YOUR_API_KEY" ...

Call your CRM Platform! Using an ASP.NET Web API to Link Twilio and Salesforce.com
I love mashups. It’s fun to combine technologies in unexpected ways. So when Wade Wegner of Salesforce asked me to participate in a webinar about ...

Resources last updated: 2/16/2016 1:18:18 PM