Cross Origin Put Request方法(Cross Origin Put Request Methods)

编程入门 行业动态 更新时间:2024-10-26 22:30:31
Cross Origin Put Request方法(Cross Origin Put Request Methods)

执行Cross Origin Put请求有哪些成功的方法? 我成功地使用代理发出了一个GET请求并将其放入下拉列表中,如此处所示>> 从API查询创建下拉列表 >>但是在制作PUT请求时无法使用相同的过程?

思考?

What are some successful methods for performing Cross Origin Put requests? I successfully used a Proxy to make a GET request and put it into a Dropdown list as can be seen here >> Create Dropdown list from API Query >>but have not been able to use the same process in making a PUT Request?

Thoughts?

最满意答案

通过在javascript中使用代理,我能够成功获得PUT请求才能工作。

$.ajaxPrefilter( function (options) { if (options.crossDomain && jQuery.support.cors) { var http = (window.location.protocol === 'http:' ? 'http:' : 'https:'); options.url = http + '//cors-anywhere.herokuapp.com/' + options.url; //options.url = "http://cors.corsproxy.io/url=" + options.url; } });

一旦代理建立,我使用chrome扩展(现在是一个桌面应用程序) Postman来获取PUT HTML代码。 这是通过首先让PUT请求在Postman中工作然后选择“代码”链接(在“发送”按钮下面)并从下拉列表中选择“JavaScript Jquery AJAX”来完成的。 以下是Postman输出代码的示例。

var settings = { "async": true, "crossDomain": true, "url": "https://[apiurl].com", "method": "PUT", "headers": { "content-type": "text/xml", "cache-control": "no-cache", "postman-token": "[token]" }, "data": "<this_is_the_xml_data_youre_sending>" } $.ajax(settings).done(function (response) { console.log(response); });

从Postman复制代码后,将代理代码和Postman javascript放入HTML页面并观察PUT请求。

I was able to successfully get a PUT request to work just peachy through the use of the proxy in javascript.

$.ajaxPrefilter( function (options) { if (options.crossDomain && jQuery.support.cors) { var http = (window.location.protocol === 'http:' ? 'http:' : 'https:'); options.url = http + '//cors-anywhere.herokuapp.com/' + options.url; //options.url = "http://cors.corsproxy.io/url=" + options.url; } });

Once the Proxy was established, I used the chrome extension (now a desktop app) Postman to get the PUT HTML code. This was done by first getting the PUT request to work in Postman and then selecting the "code" link (below the "send" button) and selecting "JavaScript Jquery AJAX" from the drop-down. Here is an example of outputted code from Postman.

var settings = { "async": true, "crossDomain": true, "url": "https://[apiurl].com", "method": "PUT", "headers": { "content-type": "text/xml", "cache-control": "no-cache", "postman-token": "[token]" }, "data": "<this_is_the_xml_data_youre_sending>" } $.ajax(settings).done(function (response) { console.log(response); });

Once the code is copied from Postman, put the proxy code and Postman javascript into an HTML page and watch the PUT request happen.

更多推荐

本文发布于:2023-08-04 14:25:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1416430.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:方法   Origin   Cross   Put   Methods

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!