使用浏览器插件RestClient模拟POST请求,可以拿到返回结果:
使用HttpHelper拿不到结果,微信返回的结果告知参数出错,是参数没传过去么?
[JavaScript] 纯文本查看 复制代码 $.ajax({
type: "POST",
url: '/NewMedia/PostWeiXinData',
data: { url: "https://api.weixin.qq.com/cgi-bin/material/batchget_material", Id: "7", type: "news", offset: 0, count: 20 },
success: function (data) {
console.log(data);
},
error: function (XMLHttpRequest, textStatus, errorThrown) {
console.log(XMLHttpRequest);
console.log(textStatus);
console.log(errorThrown);
}
});
[C#] 纯文本查看 复制代码 [HttpPost]
public ContentResult PostWeiXinData(string url, int Id)
{
var model = ser_NewMedia_WeiXin.Find(Id);
if (model == null)
{
return Content("");
}
string param = string.Empty;
for (int i = 0; i < Request.Form.Count; i++)
{
if (Request.Form.Keys[i].ToLower() != "url" && Request.Form.Keys[i].ToLower() != "id")
param += Request.Form.Keys[i] + "=" + Request.Form[i] + "&";
}
param += "access_token=" + model.Access_Token + "&";
HttpHelper http = new HttpHelper();
HttpItem item = new HttpItem()
{
URL = url,
Method = "post",
ContentType = "application/x-www-form-urlencoded",
Postdata = string.IsNullOrEmpty(param) ? null : param.Trim('&')
};
HttpResult result = http.GetHtml(item);
return Content(result.Html);
}
参数都拼接上了,跟RestClient工具一样,理论上应该能传过去的:
但是微信接口返回:
{"errcode":40004,"errmsg":"invalid media type hint: [UK3j0286e298]"}
参数type不对,其实是对的,莫非是没post过去?
|