Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
(11-13-2018, 10:35 AM)mo_ayad Wrote: I am trying to post a JSON to web rest service but always with message HTTP1.1/BAD request.

Is there any payload data in the response body to indicate what the server considered to be bad? By default, TIdHTTP raises an EIdHTTPProtocolException when it receives an HTTP error from the server, where the response payload will be in the exception's ErrorMessage property.

If you enable the hoNoProtocolErrorException and hoWantProtocolErrorContent flags in the TIdHTTP.HTTPOptions property, the EIdHTTPProtocolException will not be raised (so use the TIdHTTP.Response.ResponseCode property to know if the request was successful or not), and the response payload will be written to your TMemoryStream whether an error occurred or not.

(11-13-2018, 10:35 AM)mo_ayad Wrote: The page in question is test page:

That page says to POST to '', so why are you posting to a different URL ('')?

(11-13-2018, 10:35 AM)mo_ayad Wrote:
htpBrwsr.Request.CustomHeaders.Add('Authorization: Bearer ' + sToken); // token got correctly from previous step

Be sure to set the TIdHTTP.Request.BasicAuthentication property to False.

Other than that, I don't see anything else wrong with your code. If the server is still having problems with your HTTP request, please show the actual request that TIdHTTP is sending. Since you are using SSL/TLS, you can get that data by assigning one of the TIdLog... components to the TIdHTTP.Intercept property, which will log the request before it is encrypted, and log the response after it has been decrypted.


Messages In This Thread
Post JSON with IDHTTP - by mo_ayad - 11-13-2018, 10:35 AM
RE: Post JSON with IDHTTP - by rlebeau - 11-13-2018, 07:40 PM

Forum Jump:

Users browsing this thread: 1 Guest(s)