TWebHttpRequest

With the sample TMSWeb_SimpleService.web, using httpGET works.


I just try make a call with httpPOST with parameters that works with POSTMAN, and the only result I get as result is an error:

  WebHttpRequest1.PostData := '{"telefon":"699123456"}';
  WebHttpRequest1.Execute;

I've tried all combinations with PostData string, and always get the same result from "WebHttpRequest1Response(...AResponse...)":

{"code":"401","status":"error","msg":"NOK"}

Also, if I try to add any parameter in WebHttpRequest1.Header, we get no "Response" from "WebHttpRequest1Response" any more. For example:

cache-control: no-cache

Just after adding this line in WebHttpRequest1.Header, we don't receive Response anymore.

When something is not working as expected, please always check if there are not any errors in the browser console (hotkey F12 to open)

When testing this here, I see the CORS error in the browser console.

Access to fetch at 'https://www.xiptic.com/license/presencia-wa/web/XL_registrarEmpleat' from origin 'http://localhost:8000' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: It does not have HTTP ok status.

Please enable CORS on this server.
For CORS background:
https://stackoverflow.com/questions/27365303/what-is-the-issue-cors-is-trying-to-solve
Our call is a POST.
There error we get in Console is not about "CORS"
The message we get in Console is:
  
[Violation] 'load' handler took 1481ms

and from the service don't arrives any information about the PostData we send.
We have tryed to send it with all formats but nothing arrives to the server:

  WebHttpRequest1.PostData := '{"telefon":"699111222"}';
  WebHttpRequest1.PostData := '"telefon":"699111222"';
  WebHttpRequest1.PostData := 'telefon=699111222';

..always the sambe result in Console: [Violation] 'load' handler took...

I'm not sure in what format your server expects the data (and possibly if it expects any specifc headers to be set).
Probably the easiest way to find out is to check with a (free) tool like Fiddler about the details of a successful HTTP request versus the HTTP request you try to execute from the TMS WEB Core application.
See: https://www.telerik.com/fiddler

Solved.

It was necessary to add just one header:

 WebHttpRequest1.Headers.AddPair('Content-Type', 'application/x-www-form-urlencoded');

and now it works.

Thanks.

Thanks for informing!

1 Like