ls2ni_csdn
ls2ni_csdn
2016-03-17 22:28

请求微支付统一下单接口,远程服务器错误 404

  • 微支付
  • httpwebrequest
  • 远程服务器错误

我请求微支付统一下单接口,报错。

错误:远程服务器返回错误: (404) 未找到。
HttpWebResponse response = (HttpWebResponse)request.GetResponse();

我的代码:

图片说明

string success_return = SendQingqiu.HttpPost("https://api.mch.weixin.qq.com/pay/unifiedorde", xml);

public static string HttpPost(string url, string data)
{
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
request.Method = "POST";
request.ContentType = "text/xml";
//request.ContentType = "application/x-www-form-urlencoded";
//request.ContentLength = Encoding.UTF8.GetByteCount(data);

    byte[] bytes = System.Text.Encoding.UTF8.GetBytes(data); // 编码形式按照个人需求来设置
    request.ContentLength = bytes.Length;
    Stream requestStream = request.GetRequestStream();
    requestStream.Write(bytes, 0, bytes.Length);
    requestStream.Close(); 

    HttpWebResponse response = (HttpWebResponse)request.GetResponse();

    Stream myResponseStream = response.GetResponseStream();
    StreamReader myStreamReader = new StreamReader(myResponseStream, Encoding.GetEncoding("utf-8"));
    string retString = myStreamReader.ReadToEnd();
    myStreamReader.Close();
    myResponseStream.Close();

    return retString;
}
  • 点赞
  • 回答
  • 收藏
  • 复制链接分享

1条回答

为你推荐