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"}';
   UrlStr := EditUrl.Text + 'AirtimeRequest';
  try
   HTTPClient.Post(urlStr, Params, JsonResponse);
  except
   on E: EIdHTTPProtocolException do begin
     Memo1.lines.Add('Error');
   end;
  end;
  Memo1.Lines.Add('Response');
  Memo1.Lines.LoadFromStream(JsonResponse);

  finally
   HTTPClient.Free;
   Params.Free;
   JsonResponse.Free;
  end;
end;


Thanks
Godfrey
0
Godfrey
7/4/2014 6:16:32 AM
embarcadero.delphi.winsock 1874 articles. 2 followers. Follow

2 Replies
1605 Views

Similar Articles

[PageSpeed] 56

Godfrey wrote:

> Can you assist me(new to http) with this code.  I dont get a response.
> What am I doing wrong.

You are not posting the JSON data correctly.  Try this instead:

{code}
procedure TForm1.Button1Click(Sender: TObject);
var
  HTTPClient : TIdHTTP;
  JsonRequest : TStringStream;
  UrlStr, Response : String;
begin
  HTTPClient := TIdHTTP.Create(nil);
  try
    JsonRequest := TStringStream.Create('{"TillNo":1,"OperatorCode":1234,"ReceiptType":"String"}', 
TEncoding.UTF8);
    try
      UrlStr := EditUrl.Text + 'AirtimeRequest';
      try
        HTTPClient.Request.ContentType := 'application/json';
        HTTPClient.Request.Charset := 'utf-8';
        Response := HTTPClient.Post(urlStr, JsonRequest);
        Memo1.Lines.Text := 'Response' + sLineBreak + Response;
      except
        Memo1.Text := 'Error';
      end;
    finally
      JsonRequest.Free;
    end;
  finally
    HTTPClient.Free;
  end;
end;
{code}

--
Remy Lebeau (TeamB)
0
Remy
7/4/2014 6:08:42 PM
Thanks Remy.  Just what I need.
0
Godfrey
7/5/2014 10:57:16 AM
Reply:

Similar Artilces:

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...

Posting using HTTP GET instead of HTTP POST from Textbox control
Hi I feel almost silly asking this question, but I want to use HTTP GET instead of the default HTTP POST that asp.net uses when a user enters some text in my textbox and clicks on the associated button. How do I do that? Regards, Egil. You can explicitly specify "get" for method attribute of your form. Like this: <form id="form1" runat="server" method="get"> I am not sure why you would want to do this. This causes _VIEWSTATE to show up in your URL and as a query string. And there is a length limitation on query string. The HTML specifications technically define the...

[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...

how can I post http parameters into internet explorer.
I need to hack an http post for testing purposes. Page one.asp has a seried of dropdowns for criteria. Page two.asp lists results based on the criteria selected in page one. The pages use form post to pass parameters between themselves. No querystring params. Is there any way I can make a custom http message that posts directly to page two.asp and renders in IE? I've been using fiddler to monitor the http between the 2 pages but I don't know how to take what's createrd in fiddler and post it to internet explorer. Any help would be appreciated. Thanks Eric ...

Parsing response from HTTP Post (serialized array) in Delphi?
Hi All, I'm new to using Indy and am not sure of the best way to parse the response I am getting. It is a serialized PHP array. I need to get the data out of this array and into a record or an object. I know I can search for specific strings and work my way through to the data, but I was wondering is there was a better way iterate through the response in case they change the layout, data, names, etc. I'd just like to put it into a format where I can use name of the data to get the corresponding value. I'm using Indy 10 and Delphi 5. TIA. Here is the URL for the test ca...

Need some help on receiving a http post and decoding the parameters!?
Hi  I have a problem with a site I am currently working on. My site is to receive text (an sms message actually) from an http post. This post is from an external site and I have no control over when it is sent. The company have told me that i need to set up a handler that will receive the post and in turn decode the parameters within it. Is there some kind of page or service that will accept this post and then somehow save the message into a database.  Could somebody help me understand how to do this as I dont really know where to start and i am struggling...

How to make webservice (HTTP POST) but content parameter in XML format?
 Hi all, I'm now building a webservice using ASP.NET to receive data from SMPP server.My problem is the SMPP server post data via HTTP with content as following:POST /submitSM HTTP/1.1Host: 10.58.38.18:9080Content-Type: text/xmlContent-Length: 135<smppvas>    <sms src="888" dest="08881234567">SMS Text 1</sms>    <sms src="888" dest="08881234568">SMS Text 2</sms></smppvas> The question is how to get body of those data in websevice, so i can parsing the XML data fo...

Help in sending http post form parameters to worldpay! [:'(]
Hi guys, i really need help in the integration with worldpay payment gateway.  In order to integrate, have to send them some parameters in http post. But how to pass sessions from the previous billing.aspx to html form? I need to pass Session("amount") to the input type amount value, but have no idea how to pass the session to html input.This is my first time dealing with payment gateway, hope you guys can guide me with the code. I had stuck for serveal days. Thanks in advance. Below is a example data that required to send to worldpay.<form action="https://se...

how to construct a http-post request in code for multiple parameters function call?
Hi, I have the following code to make a call to the webmethod that takes one parameter.I am wondering how can I call a webmethod with 2 parameters? wReqRouter = WebRequest.Create(sbURL.ToString()); wReqRouter.Method="POST"; wReqRouter.ContentType="application/x-www-form-urlencoded"; string QueryString="sName="+sName; System.Text.UTF8Encoding encoding=new UTF8Encoding(); byte[] buffer=encoding.GetBytes(QueryString); wReqRouter.ContentLength=QueryString.Length; Stream objStream=wReqRouter.GetRequestStream(); objStream.Write(buffer...

Using HTTP Post for passing Parameters in SQL Server Reporting Services
Hi All We have requirement where when users logs in into the system and view report.In report he can see data specific to user who is running the report. For this we have created a parameter in report but the problem is UserId Parameter is visible in Query String, which we don't want as USer might change the userid and can see the other users data which is security issue.I was goingh through newsgroups i got the answer was using HTTP POST but problem is when i am using this i am not getting any parameters in query string in Address bar of browser but when user right clicks and view the pr...

HTTP Post & HTTP Get
Hi, We have a web service written in .net 1.0 which is using the post & get protocols. When we installed .net 1.1 on the server hosting the app the web service stopped working. We found that this was because in the 1.1 machine config the post and get protocols are disabled so we enabled and alls well again. What i don't understand though is why its happening! The web service is written in .net 1.0 so surely it should be looking at the 1.0 machine.config which does have the protocols enabled rather than the 1.1 config that does not have the protocols enabled. Event...

How do you post XML via http post
I have the xml code below and I need to post it via HTTP POST  to this site http://dmp.dynmark.com/XmlHttp/MessageMTSend.aspx                     "<?xml version='1.0' encoding='utf-8'?> "                     "<Dmp xmlns='http://dmp.dynmark.com/XmlHttp/MessageMTSend.xsd' version='1.0'>"                &n...

Code regardin post: Spread 8 COM
This message is in MIME format. Since your mail reader does not understand this format, some or all of this message may not be legible. --JivePart=_5f856.zeB8CwDOH5aMJzMl Content-Type: text/plain; charset="Utf-8" Code samples Spread Custom Cell Sample.zip = Delphi code Spread_ActiveX_Samples.zip = GrapeCity sample (VB, VC) -- Regards, Ronald Hoek Application Developer ComponentAgro B.V. Oud-Beijerland - The Netherlands http://www.componentagro.nl KvK: H24264020 --JivePart=_5f856.zeB8CwDOH5aMJzMl Content-Type: application/zip; name="Spread_Act...

Post same post parameters received to another server
I posted on this before, but I didn't exactly get an exact answer.  I need to know how I can repost the same variables that I receive from a service (namely PayPal's IPN) to another page.I also need to know how I can just send a "202" with the same variables to the server (a specific page on the server) so that it will stop sending me the instant payment notifications.Thank you for any help,Joshua Foulk      For your first problem, have a look at these artciles on cross page postback:  http://msdn2.microsoft.com/en-us/library/ms178139.aspx ...

Web resources about - HTTP post with json parameters - embarcadero.delphi.winsock

Parameter - Wikipedia, the free encyclopedia
A parameter (from the Ancient Greek παρά , "para", meaning "beside, subsidiary" and μέτρον , "metron", meaning "measure"), in its common meaning, ...

fb_source Parameter - Facebook-Entwickler
This document lists the complete list of values for the fb_source parameter that is returned with th...

Google / Firefox Parameter - Flickr - Photo Sharing!
HS what? www.seroundtable.com/archives/017105.html

Cat 8: TIA performance standards committee chairman previews parameters of forthcoming twisted-pair cable ...
Category 8, the next-generation twisted-pair cabling specification, is still in development, but the outlook looks quite positive that it will ...

Philippine president asks for 'parameters' of Mayon Volcano tours
Philippine president asks for 'parameters' of Mayon Volcano tours People's Daily Online ... 26, 27, 28, 29, 30, 31. Jan, Feb, Mar, Apr, May, ...

Alternatives to boolean parameters
... ) { PrintLine ( item . Name ); if ( printDetails ) { PrintLine ( item . Description ); } } } Aha! Now can see that the boolean parameter ...

Exporting Error (Error in Parameter...: Apple Support Communities
This site contains user submitted content, comments and opinions and is for informational purposes only. Apple disclaims any and all liability ...

Apple tech monitors device aging, adjusts operating parameters to ensure optimal performance
... describing a method of monitoring the aging of a device's electronics, comparing the data with a global average and modifying operating parameters ...

Is it poor programming practice to pass parameters as objects?
... a free, community-powered network of 100+ Q&A sites . Risser asked: So, we've got a guy who likes to write methods that take Objects as parameters, ...

Parameter Short Film Competition sponsored by Grolsch
Grolsch presents Parameter The A.V. Club Short Film Competition Please Enter Your Date of Birth Ineligible entry Enter For people over the age ...

Resources last updated: 12/28/2015 6:39:34 AM