急!搞了我一夜还是不行!GetResponseStream()返回乱码!怎么修改encoding都不成!求老师们帮帮忙!
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部分的代码是否正确呢?希望老师们帮我看一下,被这个问题搞死了!
附上正常返回的值:
...全文
相关推荐
c#使用nsoup解析html乱码解决方法分享 nsoup教程
NSoup是JSoup的Net移植版本。使用方法基本一致。如果项目涉及HTML的处理,强烈推荐NSoup。但是遗憾的是NSoup默认的编码是UTF-8,处理中文有乱码,下面给出二种解决方法
asp.net页面通过URL参数传值中文乱码问题解决办法
asp.net页面通过URL参数传值中文乱码问题解决办法
.Net获取URL中文参数值的乱码问题解决方法总结
主要介绍了.Net获取URL中文参数值的乱码问题解决方法,总结分析了针对URL参数传递中出现的乱码问题与相应的解决方法,具有一定参考借鉴价值,需要的朋友可以参考下
解决网爬工具爬取页面信息出现乱码的问题_asp.net技巧.doc
解决网爬工具爬取页面信息出现乱码的问题_asp.net技巧.doc
浅谈C#中HttpWebRequest与HttpWebResponse的使用方法
本篇文章主要介绍了浅谈C#中HttpWebRequest与HttpWebResponse的使用方法,具有一定的参考价值,有兴趣的可以了解一下。


