C# 源代码是POST请求返回字符串流。由于现在返回的是一个网页平台,如何调整。请大神帮忙修改一下

public static String CreatePostHttpResponse(string url, IDictionary parameters, Encoding charset)
{
HttpWebRequest request = null;
//HTTPSQ请求

ServicePointManager.ServerCertificateValidationCallback = new RemoteCertificateValidationCallback(CheckValidationResult);
request = WebRequest.Create(url) as HttpWebRequest;
request.ProtocolVersion = HttpVersion.Version10;
request.Method = "POST";
request.ContentType = "application/x-www-form-urlencoded";
request.UserAgent = DefaultUserAgent;
//如果需要POST数据

if (!(parameters == null || parameters.Count == 0))
{
StringBuilder buffer = new StringBuilder();
int i = 0;
foreach (string key in parameters.Keys)
{
if (i > 0)
{
buffer.AppendFormat("&{0}={1}", key, parameters[key]);
}
else
{
buffer.AppendFormat("{0}={1}", key, parameters[key]);
}
i++;
}
byte[] data = charset.GetBytes(buffer.ToString());
using (Stream stream = request.GetRequestStream())
{
stream.Write(data, 0, data.Length);
}
}

     Stream outstream = request.GetResponse().GetResponseStream();   //获取响应的字符串流  
      StreamReader sr = new StreamReader(outstream); //创建一个stream读取流  
        return sr.ReadToEnd(); 

2个回答

我有个封装好的。你拿过去直接用就可以了。
代码在github:
github.com/Dhugjil/DFrame/blob/master/DFrame.Common/HttpService.cs
封装在common层里。
干活,全是好东西哦,可以拿过去学习。
不用谢,采纳就好。

什么意思?返回2进制,而不是字符串?

Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问
相关内容推荐