2016-12-13 1 views
0

Cross Origin Put 요청을 수행하는 성공적인 방법은 무엇입니까? 프록시를 사용하여 GET 요청을 만들고 여기에 표시된대로 >>Create Dropdown list from API Query >> 드롭 다운 목록에 넣었습니다. PUT 요청을 만들 때 동일한 프로세스를 사용할 수 없었습니까?교차 기점 Put 요청 방법

생각하십니까?

답변

1

나는 성공적으로 자바 스크립트에서 프록시의 사용을 통해 복숭아 작업을 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; 
    } 
}); 

, 나는 PUT의 HTML 코드를 얻을 수있는 크롬 확장 (현재 데스크톱 응용 프로그램) Postman을 사용했다. 이것은 먼저 Postman에서 PUT 요청을 받고 "코드"링크 ("보내기"버튼 아래)를 선택하고 드롭 다운에서 "JavaScript Jquery AJAX"를 선택하여 수행되었습니다. 다음은 우편 배달부에서 출력 된 코드의 예입니다. 코드가 우체부에서 복사하면

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); 
}); 

, HTML 페이지에 프록시 코드 및 우편 배달 자바 스크립트를 넣고 PUT 요청이 발생보세요.