2012-05-11 5 views
0

HTTP 리소스로 노출 된 외부 도메인에서 원격 "서비스"를 호출해야합니다. 서비스는 POST 요청 만 수락합니다.POST로 고전 asp 크로스 도메인 HTTP 요청

POST 메서드를 지원하지 않으므로 JSONP를 사용할 수 없습니다. AJAX 요청은 상호 도메인 요청이므로 사용할 수 없습니다.

단순한 솔루션은 ServerXMLHTTP 개체를 사용하여 요청을 관리하는 것입니다. 단점은 ServerXMLHTTP를 사용하면 요청이 동기식이라는 것입니다.

아이디어가 있으십니까?

+0

가 ([이]를 살펴 보자 http://stackoverflow.com/questions/1576040/synchronous-cross-sub-domain-post-request-with-jquery) SO 스레드. –

답변

1

ServerXMLHTTP는 앱에서 호스팅하는 서버 측 코드에서 사용되므로 동기화되어 있어도이 페이지를 호출하면 일반 XmlHttp를 사용하여 비동기가 될 수 있으므로 앱과 관련이 있습니다. 본질적으로 브라우저의 사이트 간 스크립팅 제한을 극복하기 위해 서버에 프록시를 만듭니다.

서버 측 :

<% Function RemoteMethod1(ByVal param1, ByVal param2) 'Use ServerXMLHttp to make a call to remote server RemoteMethod = ResultFromRemoteServer End Function Function RemoteMethod2(ByVal param1, ByVal param2) 'Use ServerXMLHttp to make a call to remote server RemoteMethod = ResultFromRemoteServer End Function 'Read QueryString or Post parameters and add a logic to call appropriate remote method sRemoteMethodName = Request.QueryString("RemoteMethodName") If (sRemoteMethodName = RemoteMethod1) Then results = RemoteMethod1(param1, param2) Else If (sRemoteMethodName = RemoteMethod2) Then results = RemoteMethod1(param1, param2) End If 'Convert the results to appropriate format (say JSON) Response.ContentType = "application/json" Response.Write(jsonResults) %> 

Proxy.asp

지금 (jQuery의해서 getJSON 말) AJAX를 사용하여 클라이언트 측에서이 Proxy.asp를 호출합니다. 따라서 서버가 차단되는 동안 클라이언트의 호출은 여전히 ​​비동기입니다.

클라이언트 측 :

$.getJSON('proxy.aspx?RemoteMethodName=RemoteMethod1&Param1=Val1&Param2=Val2', function(data) { 
    // data should be jsonResult 
});