コードビハインド Web メソッドへの jquery ajax POST があります。その webmethod で、json を返すサードパーティの Web API サービスに対して HttpWebRequest を実行します。httpwebrequest は正常に機能しますが、ブラウザーにポップアップが表示され、資格情報の入力を求められます (認証が必要です)。私のマシンではこれはうまく機能しますが、展開すると、httpwebrequest 呼び出しからデータが返されない場合を除いて機能しません。
jquery 呼び出し:
function serverCall(httpMethod, pageName, methodName, inputData, successCallback, errorCallback, disableGlobalAjaxEvents) {
// Construct the url
var url = pageName + "/" + methodName;
var triggerGlobalEvents = true;
if (disableGlobalAjaxEvents && disableGlobalAjaxEvents == true) {
triggerGlobalEvents = false;
}
$.ajax({
type: httpMethod,
url: url,
data: JSON.stringify(inputData),
contentType: "application/json; charset=utf-8",
global: triggerGlobalEvents,
dataType: "json",
success: function(msg) {
if (successCallback) {
var parsedObject = JSON.parse(msg.d);
successCallback(parsedObject);
}
},
error: function(error, status) {
if (errorCallback) {
errorCallback(error, status);
}
}
});
そして、実際の呼び出しは次のとおりです。
serverCall("POST", "SomePage.aspx", "GetSomething", inpuData, onSuccess, onError, true);
ウェブメソッド:
[WebMethod(
CacheDuration = 5,
EnableSession = true)]
public static string GetSomething(string user, string item)
{
// In the body i do the HTTPWebRequest that returns JSON
}