<![CDATA[解析 XML 出错 (位置: /body): <unspecified file>(1): expected <]]> 微信支付统一下单
时间:2021-01-16 11:45:12
收藏:0
阅读:0
今天突然就微信支付就调不起来了,而且我找了一个相同代码的项目,查看了他的微信支付,并没有异常。奇怪之余,进入微信交流社区搜索相关问题,没想到遇到同样问题的。从他们的交流间的到解决办法。如下:
原来:
private static string sendPost2(string URL, string urlArgs) { System.Net.WebClient wCient = new System.Net.WebClient(); wCient.Headers.Add("Content-Type", "application/x-www-form-urlencoded"); byte[] postData = System.Text.Encoding.ASCII.GetBytes("body=" + urlArgs); byte[] responseData = wCient.UploadData(URL, "POST", postData); string returnStr = System.Text.Encoding.UTF8.GetString(responseData);//返回接受的数据 return returnStr; }
修改:
public static string sendPost(string url, string content) { string result = ""; HttpWebRequest req = (HttpWebRequest)WebRequest.Create(url); req.Method = "POST"; req.ContentType = "application/x-www-form-urlencoded"; #region 添加Post 参数 byte[] data = Encoding.UTF8.GetBytes(content); req.ContentLength = data.Length; using (Stream reqStream = req.GetRequestStream()) { reqStream.Write(data, 0, data.Length); reqStream.Close(); } #endregion HttpWebResponse resp = (HttpWebResponse)req.GetResponse(); Stream stream = resp.GetResponseStream(); //获取响应内容 using (StreamReader reader = new StreamReader(stream, Encoding.UTF8)) { result = reader.ReadToEnd(); } return result; }
估计原来代码中有 “body=” 的原因
导致原因:可能是微信调整了请求的body格式,影响面好像不是全部商户,因为我看了另外一个项目没有出现这个错误
社区原文链接:https://developers.weixin.qq.com/community/develop/doc/000802951181a899d08b7dd9a5bc00
评论(0)