Page 1 of 1

schttpwebrequest response

Posted: Wed 18 Aug 2021 09:03
by clement75
Hi,
i use the schttpwebrequest to connect one URL in delphi program
it can receive the response when the response is:
{
"success": true
}

however, it raise exception (Bad Request) when the server return the below message:
{
"success": false,
"error": "Given code / id does not exists "
}

the error happens in the below code:
Response := ScHttpWebRequest1.GetResponse;


Anyone know how can i get/read the data returned from the server?


Thank You.

Re: schttpwebrequest response

Posted: Thu 19 Aug 2021 12:04
by YanishevskiyVI
Hi Clement!

Thank you for your question!

In order to get data returned by server you need to handle HttpException. Try to do this:

Code: Select all

  try
    Response := ScHttpWebRequest1.GetResponse; 
  except
    on E:HttpException do
      showmessage(E.ServerMessage);
  end;
In this case E.ServerMessage will contain all data returned by server.

Please, let us know if tere are any questions!

Regards,
Vitaliy
Devart team

Re: schttpwebrequest response

Posted: Fri 20 Aug 2021 01:27
by clement75
thanks for your reply.
it works!

Re: schttpwebrequest response

Posted: Fri 20 Aug 2021 11:07
by YanishevskiyVI
Hi Clement!

Thank you for your reply!

I am glad to know that the issue was resolved successfully for you!

In case you meet any other issues or have any questions please feel free to contact us back.

Regards,
Vitaliy