2016-12-13 45 views

回答

1

我能夠通過在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 JavaScript放入HTML頁面並觀察PUT請求發生。