Author Topic: POST to URL?  (Read 665 times)

Chilkat

  • Administrator
  • Full Member
  • *****
  • Posts: 103
  • Karma: +6/-0
    • View Profile
POST to URL?
« on: January 04, 2018, 01:38:26 PM »
I want to send a simple HTTP POST and I am a little bit lost in all your functions.
For example, I want to send:
 
https://testserver.com:443/rest/site/raffletest/pinGeneratorService/reqPin?requestId=123&terminalId=%22term1%22&amount=2000

How can I do that ?  I already tried your JSON, REST functions, etc. with not a lot of success.
Do you have any example in C language,

Chilkat

  • Administrator
  • Full Member
  • *****
  • Posts: 103
  • Karma: +6/-0
    • View Profile
Re: POST to URL?
« Reply #1 on: January 04, 2018, 01:47:46 PM »
The POST method is designed to send input data to the server.  What you have is a URL where the query parameters are encoded within the URL.  Given that there is no data other than what's embedded within the URL, one would typically send a GET -- because there's no body part of the HTTP request.  In other words, the Content-Length is 0.

The way to send the equivalent, but as a POST, is to send a request where the query params are placed in the body of the request.  The Content-Type of the request is "x-www-form-urlencoded".  You would use the Http.PostUrlEncoded method.

The url passed to PostUrlEncoded would include the path, but not the query params.
For example, in pseudo-code:

Code: [Select]
HttpResponse response = http.PostUrlEncoded("https://testserver.com:443/rest/site/raffletest/pinGeneratorService/reqPin", req);

The req object is an HttpRequest object that was loaded with the query params.  For example, in pseudo-code:
Code: [Select]
HttpRequest req = new HttpRequest();
req.AddParam("requestId","123");
req.AddParam("terminalId","term1");
req.AddParam("amount","2000");