0
我消耗在MVC控制器第三方API,以便將JSON返回自己的JavaScript端點在我的網站(簡單的答案爲「爲什麼」爲提高安全性 - 他們形容這是一個「中繼」),在這個過程中,我使用Web客戶端:消耗在MVC控制器第三方API時要返回整個響應
public ActionResult relay (string link)
{
// some code here to insert an access token into their json (on the request's content stream), and reserialise.
string result = "";
using (WebClient client = new WebClient)
{
client.Headers[HttpRequestHeader.ContentType] = "application/json";
try
{
result = client.UploadString(ApiUrl + link, "POST", jsonParamsFrom3rdpartyJS);
}
catch (WebException ex)
{
HttpWebResponse _errorResponse = (HttpWebResponse) ex.Response;
if (errorResponse.StatusCode == HttpStatusCode.PaymentRequired)
{
ErrorLogger.WriteToErrorLog("Need to pay the 3rd party");
}
}
}
return Json(result);
}
有什麼辦法,我可以返回來自第三方的javascript整個響應?它看起來像是有一些JSON在響應中出現錯誤消息,但無法獲得它也期待收到402響應的JavaScript(這可能被困在別處?)