Welcome! Log In Create A New Profile

Advanced

Webservice calls and CORS

Posted by pauly139 
Webservice calls and CORS
August 25, 2023 06:24AM
I've created some webservices that use a passed JSON variable in the content section of the httprequest. All works fine when I call from windev code in another app. However I wrote some javascript to call it, and it works fine on localhost, but when I call it on a production server, the javascript call fails with a CORS error. Using apache server.
I tried using 'no-cors' mode in the call, but then I can't use JSON in the content.
Anyone know how I can resolve this? I'd like to stick to using JSON content in the call.



Edited 1 time(s). Last edit at 08/25/2023 08:11AM by pauly139.
Re: Webservice calls and CORS
August 25, 2023 08:11AM
Following on, I've tried modifying the conf file in apache with the line

Header set Access-Control-Allow-Origin "*"

but obviously I'm not putting it in the right place. Anyone know where it goes in relation to the WB App Server entries?
Re: Webservice calls and CORS
August 25, 2023 11:15AM
Hi Pauly

This is the way to do it:
- Add an 'options' method to your post/get/... web service definition.
See Afbeelding1.png
- In there you do a call to set the CORS options for the endpoint.
See Afbeelding2.png

Cheers

Peter
Attachments:
open | download - Afbeelding1.png (145.9 KB)
open | download - Afbeelding2.png (119.6 KB)
Re: Webservice calls and CORS
August 26, 2023 12:19AM
Hi Pete - thanks for jumping in and helping out.

I added then OPTIONS method, and same code, but still no joy.

Does the apache conf file need any corresponding changes? Does it matter where the associated procedure for the OPTIONS method is (mine is in a global procedure)?

One clue is I put some trace code in that procedure, and it seems it is never executed.

Thanks for helping out...

Rgds
Paul



Edited 1 time(s). Last edit at 08/26/2023 12:22AM by pauly139.
Attachments:
open | download - Screenshot 2023-08-26 081629.png (24.7 KB)
open | download - Screenshot 2023-08-26 081712.png (43.9 KB)
Re: Webservice calls and CORS
August 28, 2023 04:19AM
Continuing the saga - I can see the http Header coming back correctly - see attached screenshots, but still the CORS error fires. I've also posted the javascript code calling the service. Perhaps the problem is my javascript (wouldn't be surprised :-))

Thanks to anyone who takes the time to have a look.
Attachments:
open | download - js code.png (20.6 KB)
open | download - browser debug.png (117.7 KB)
Author:

Your Email:


Subject:


Spam prevention:
Please, enter the code that you see below in the input field. This is for blocking bots that try to post this form automatically. If the code is hard to read, then just try to guess it right. If you enter the wrong code, a new image is created and you get another chance to enter it right.
Message: