0
嘗試使用Request.Form獲取已發佈的有效內容,但Request.Form始終{}爲空?Request.Form空郵件數據
這裏是我的有效載荷:
但是當我嘗試和使用:
var responseBytes = Request.HttpMethod == "POST" ? client.UploadValues(url, Request.Form) : client.DownloadData(url);
我載荷的Request.Form是空的。
整個C#代碼:
public ActionResult Index(string pathInfo)
{
var url = Settings.GetValue<string>("QualService") + "/" + pathInfo + "?" + Request.QueryString;
//Get stuff from the back end
using (var client = new WebClient())
{
client.Headers[HttpRequestHeader.ContentType] = "application/json";
client.Headers[HttpRequestHeader.Cookie] = Request.Headers["Cookie"];
client.Headers[HttpRequestHeader.Authorization] = "Basic " +
Convert.ToBase64String(
Encoding.UTF8.GetBytes(
"x:{0}".Fmt(UserSession.ApiKey)));
try
{
var responseBytes = Request.HttpMethod == "POST" ? client.UploadValues(url, Request.Form) : client.DownloadData(url);
var result = new ContentResult();
result.Content = Encoding.UTF8.GetString(responseBytes);
result.ContentEncoding = Encoding.UTF8;
result.ContentType = "application/json";
return result;
}
catch(Exception e)
{
Logger.Error("Error while proxying to the API: ", e);
}
}
return Json(false);
}
我想我發現了這個問題。 Application/json是帖子。 – allencoded
你是如何通過$ .ajax()發出POST請求的?您可能需要更改'contentType'值以滿足您的需求。 –
$ http角度它會自動給你contentType應用程序/ json – allencoded