急!搞了我一夜还是不行!GetResponseStream()返回乱码!怎么修改encoding都不成!求老师们帮帮忙!

woshichuanqi22 woshichuanqi22 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
using System;
using System.Collections.Generic;
using System.Text;
using System.IO;
using System.Net;
namespace alvvtest
{
class Program
{
static void Main(string[] args)
{
string postzf = "pageindex=1";
string url = "http://www.alivv.com/ajax/Alivv.AjaxRun.WebSiteAjax,Alivv.AjaxRun.ashx?_method=BuyerWebSiteList&_session=r";


HttpWebRequest newqq = null;
HttpWebResponse newfh = null;


System.Net.ServicePointManager.Expect100Continue = false;
Uri newurl = new Uri(url);
newqq = (HttpWebRequest)WebRequest.Create(newurl);
string data = postzf;
newqq.Host = "www.alivv.com";
newqq.UserAgent = "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; GTB6; .NET CLR 2.0.50727; CIBA)";
newqq.Accept = "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8";
newqq.Headers.Add("Accept-Language", "zh-cn,zh;q=0.8,en-us;q=0.5,en;q=0.3");
newqq.Headers.Add("Accept-Encoding", "gzip, deflate");
newqq.Headers.Add("DNT", "1");
newqq.ContentType = "text/plain; charset=UTF-8";

newqq.Referer = "http://www.alivv.com/links_gd.html";

newqq.CookieContainer = new CookieContainer() ;
newqq.Accept = "*/*";
newqq.Method = "POST";
newqq.Timeout = 60000;
//newqq.KeepAlive = true;

//newqqt.AllowAutoRedirect = true;
byte[] byteArray = Encoding.UTF8.GetBytes(data);
Stream stream = newqq.GetRequestStream();

stream.Write(byteArray, 0, byteArray.Length);
stream.Close();
newfh = (HttpWebResponse)newqq.GetResponse();
StreamReader sr = new StreamReader(newfh.GetResponseStream(), Encoding.UTF8);
string fanhuizhi = sr.ReadToEnd();



}
}
}


最后的fanhuizhi是乱码不管怎么修改encoding都不行

目前我发现在头协议当中有一句:

newqq.Headers.Add("Accept-Encoding", "gzip, deflate");

难道说信息流通过压缩了?

还有就是post部分的代码是否正确呢?希望老师们帮我看一下,被这个问题搞死了!

附上正常返回的值:
...全文

相关推荐

评论 6
收藏 已收藏
分享
返回顶部
woshichuanqi22
C# 111,130 成员 642,541 内容