TScHttpWebRequest - Exception

Discussion of open issues, suggestions and bugs regarding network security and data protection solution - SecureBridge
Post Reply
clement75
Posts: 5
Joined: Tue 06 Jul 2021 05:52

TScHttpWebRequest - Exception

Post by clement75 » Wed 08 Dec 2021 14:03

Hi,
I cannot get the exact server message of exception in the 2nd URL call. the below is my code.

1) First URL call no error:
try
Try
vHttpWebRequest := TScHttpWebRequest.Create(URL1);
vHttpWebRequest.Method := rmGET;
vHttpWebRequest.Accept := 'application/json';
vHttpWebRequest.ContentType := 'application/json';
vHttpWebRequest.KeepAlive := True;
vWebResponse := vHttpWebRequest.GetResponse;
vResponseStrRequest := vWebResponse.ReadAsString;
Except
on E : HttpException do
begin
vTmpStr := 'Error Code: ' + IntToStr(E.Code) + ' | ' +
'Server Message: ' + E.ServerMessage + ' | ' +
'Message: ' + E.Message;

raise Exception.Create(vTmpStr);
end;
on E: Exception do
begin
raise Exception.Create(E.Message);
end;
End;
Finally
vHttpWebRequest.Free;
end;

2) 2nd URL call has error, but cannot get the exact server message.
try
Try
vHttpWebRequest := TScHttpWebRequest.Create(URL2);
vHttpWebRequest.Method := rmPOST;
vHttpWebRequest.Accept := 'application/json';
vHttpWebRequest.ContentType := 'application/json';
vHttpWebRequest.KeepAlive := True;

vBuffer := TEncoding.UTF8.GetBytes(xxxxxxxxxxxxx);
vHttpWebRequest.ContentLength := Length(vBuffer);
vHttpWebRequest.WriteBuffer(vBuffer);
vWebResponse := vHttpWebRequest.GetResponse;
vResponseStrRequest := vWebResponse.ReadAsString;

Except
on E : HttpException do
begin
vTmpStr := 'Error Code: ' + IntToStr(E.Code) + ' | ' +
'Server Message: ' + E.ServerMessage + ' | ' +
'Message: ' + E.Message;

raise Exception.Create(vTmpStr);
end;
on E: Exception do
begin
raise Exception.Create(E.Message);
end;
End
Finally
vHttpWebRequest.Free;
end;

If i use Postman to test the URL2, it can return the server message 'Error: xxxxxxxxxxxxxxxxxx'.
However, if i run the my program to call the URL, it return other error message.
(if I only run the 2nd URL call, then can get the exact server message)
what is wrong in my code?

Thank you.

clement75
Posts: 5
Joined: Tue 06 Jul 2021 05:52

Re: TScHttpWebRequest - Exception

Post by clement75 » Thu 09 Dec 2021 03:13

problem solved. ignore this topic

YanishevskiyVI
Devart Team
Posts: 70
Joined: Wed 02 Jun 2021 09:30

Re: TScHttpWebRequest - Exception

Post by YanishevskiyVI » Thu 09 Dec 2021 11:24

Glad to hear that your issue is resolved.
Feel free to contact us anytime in case you get any other questions.

Regards,

Post Reply