翻看到自己原来的一段代码,看到当时为了解决这个问题时的写的一段代码!但现在又忘了!还是记下的好!
HttpWebResponse response = request.GetResponse() as HttpWebResponse;
if (response.StatusCode==HttpStatusCode.OK)
{
string characterSet = response.CharacterSet;
Encoding encode;
if (characterSet!="")
{
encode = Encoding.GetEncoding(characterSet);
}
else
{
encode = Encoding.Default;
Stream receiveStream = response.GetResponseStream();
StreamReader reader = new StreamReader(receiveStream,encode);
char[] read = new char[255];
// 每次读取255
int count = reader.Read(read, 0, 255);
while(count>0)
{ // 如果读到一定数目的字符串后,将这些字符串输入到string中
str += new String(read,0, count);
count = reader.Read(read, 0, 255); // 再读下面的255内容
}
// 读取完毕
reader.Close();
receiveStream.Close();
}
}
if (response.StatusCode==HttpStatusCode.OK)
{
string characterSet = response.CharacterSet;
Encoding encode;
if (characterSet!="")
{
encode = Encoding.GetEncoding(characterSet);
}
else
{
encode = Encoding.Default;
Stream receiveStream = response.GetResponseStream();
StreamReader reader = new StreamReader(receiveStream,encode);
char[] read = new char[255];
// 每次读取255
int count = reader.Read(read, 0, 255);
while(count>0)
{ // 如果读到一定数目的字符串后,将这些字符串输入到string中
str += new String(read,0, count);
count = reader.Read(read, 0, 255); // 再读下面的255内容
}
// 读取完毕
reader.Close();
receiveStream.Close();
}
}