跨源 Put 请求方法
Cross Origin Put Request Methods
执行 Cross Origin Put 请求的成功方法有哪些?我成功地使用代理发出 GET 请求并将其放入下拉列表中,如下所示 >> >> 但是在发出 PUT 请求时无法使用相同的过程?
想法?
通过使用 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 中工作然后选择 "code" link(在 "send" 按钮下方)并从下拉列表中选择 "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 请求的发生。
执行 Cross Origin Put 请求的成功方法有哪些?我成功地使用代理发出 GET 请求并将其放入下拉列表中,如下所示 >>
想法?
通过使用 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 中工作然后选择 "code" link(在 "send" 按钮下方)并从下拉列表中选择 "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 请求的发生。