简体   繁体   English

进行多个休息获取请求并保存输出

[英]Make multiple rest get requests and save output

I need to call a REST-ful webservice in using a GET method with some parameters and save the output of the same. 我需要使用带有一些参数的GET方法来调用REST-ful Web服务,并保存相同的输出。

My first approach was to make some requests in JavaScript and log the output using console.log() , but the server doesn't allow CORS. 我的第一种方法是使用JavaScript发出一些请求,并使用console.log()记录输出,但是服务器不允许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? 是否有任何软件可以让我创建一个数组,例如使用100个参数,保存100个调用,或者有什么更好的方法呢? PHP script? PHP脚本?

ps I can't activate CORS in the server, nor can I place code in the same domain. ps我无法在服务器中激活CORS,也无法将代码放置在同一域中。 So far I have an example I can call in the browser and have the XML return. 到目前为止,我有一个示例可以在浏览器中调用并返回XML。

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. 就CORS而言,这与您所运行的API有关,该API不允许从其他域发出请求。 This could be fixed by allowing CORS in the API you are developing on. 可以通过在您正在开发的API中允许CORS来解决此问题。

CORS Link: https://developer.mozilla.org/en-US/docs/Web/HTTP/Access_control_CORS CORS链接: 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. 另一种选择是让您的网站与API位于同一域中。

Once you have done that, you can simply make multiple AJAX requests to the API. 完成此操作后,您只需向API发出多个AJAX请求即可。

AJAX HTTP GET example: HTTP GET request in JavaScript? AJAX HTTP GET示例: JavaScript中的HTTP GET请求?

EDIT: 编辑:

You might also have to enable CORS in the HTTP header of your request. 您可能还必须在请求的HTTP标头中启用CORS。 This would have to be added to an AJAX request: 这将必须添加到AJAX请求中:

 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 这里特别是对jquery的有用链接: 如何获得跨域资源共享(CORS)发布请求的工作

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM