2 ls2ni csdn ls2ni_csdn 于 2016.03.18 06:28 提问

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

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

错误:远程服务器返回错误: (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个回答

u011012311
u011012311   2016.03.18 07:52
已采纳

请先确保url是正确的

Csdn user default icon
上传中...
上传图片
插入图片
准确详细的回答,更有利于被提问者采纳,从而获得C币。复制、灌水、广告等回答会被删除,是时候展现真正的技术了!