0

I need to call a REST-ful webservice in using a GET method with some parameters and save the output of the same.

My first approach was to make some requests in JavaScript and log the output using console.log(), but the server doesn't allow CORS. So I can't make it that way.

I am pretty sure this might be a common thing but I can't seem to find a simple way to do it. What would be the simplest way to do it? Is there any software that would allow me to make an array, let's say with 100 parameters, save 100 calls or what would be a better way to do it? PHP script?

p.s. I can't activate CORS in the server, nor can I place code in the same domain. So far I have an example I can call in the browser and have the XML return.

Sᴀᴍ Onᴇᴌᴀ
  • 8,218
  • 8
  • 36
  • 58
João Mourão
  • 168
  • 1
  • 3
  • 14

1 Answers1

0

As far as CORS is concerned, that has to do with the API you're running on not allowing requests to be made from a different domain. This could be fixed by allowing CORS in the API you are developing on.

CORS Link: https://developer.mozilla.org/en-US/docs/Web/HTTP/Access_control_CORS

The other option would be to have your website on the same domain as the API.

Once you have done that, you can simply make multiple AJAX requests to the API.

AJAX HTTP GET example: HTTP GET request in JavaScript?

EDIT:

You might also have to enable CORS in the HTTP header of your request. This would have to be added to an AJAX request:

 Access-Control-Request-Headers: x-requested-with

Here is a helpful link for jquery in particular: How to get a cross-origin resource sharing (CORS) post request working

Community
  • 1
  • 1
Alex Palacios
  • 389
  • 2
  • 4
  • 19
  • in this case i cant activate CORS on the server, neither i can have code in the same domain – João Mourão Mar 31 '17 at 00:36
  • If you do not have access to the server code, then I would recommend trying to add the CORS header in your HTTP request to see if that works. If that works, then CORS is already enabled on the server. If not, I'm not sure if you would even be able to make a request to the server unless you are on the same domain. – Alex Palacios Mar 31 '17 at 12:11