读书人

网络编程的一个有关问题

发布时间: 2013-09-05 16:02:07 作者: rapoo

网络编程的一个问题


Encoding encoding = Encoding.GetEncoding( "GB2312 ");
string strUrl = @ "http:// " + DefaultIP + " " + DefaultUrl + " ";
string postData = "username= "+UserName+ "&password= "+password+ "&area_c=&telfile1= "+TelePhones+ " ";
byte[] data = encoding.GetBytes(postData);
// 准备HTTP请求...
System.Net.HttpWebRequest myRequest = (System.Net.HttpWebRequest)System.Net.WebRequest.Create(strUrl);
myRequest.Method = "POST ";
myRequest.ContentType = "application/x-www-form-urlencoded "; //运行提示无法按照请求设置空的或空白的方法
myRequest.ContentLength = data.Length;


System.IO.Stream newStream = myRequest.GetRequestStream();
// 发送数据
newStream.Write(data, 0, data.Length);
newStream.Close();
//HTTP响应
System.Net.HttpWebResponse myResponse = (System.Net.HttpWebResponse)myRequest.GetResponse();
System.IO.Stream receiveStream = myResponse.GetResponseStream();
Encoding encode = System.Text.Encoding.GetEncoding( "GB2312 ");
System.IO.StreamReader readStream = new System.IO.StreamReader(receiveStream, encode);
Char[] read = new Char[256];
int count = readStream.Read(read, 0, 256);


StringBuilder sb = new StringBuilder( " ");
while (count > 0)
{
String readstr = new String(read, 0, count);
sb.Append(readstr);
count = readStream.Read(read, 0, 256);
}
myResponse.Close();
readStream.Close();



运行到
 myRequest.ContentType   =   "application/x-www-form-urlencoded ";
提示我无法按照请求设置空的或空白的方法,不知道怎么解决。另外我想用这个代码写91基金的接口,懂得能和我说说能成不 网络编程 无法按照请求设置空的或空白的方法 接口


[解决办法]
所有字符串最后怎么都有一个空格,明显不正常。

读书人网 >C#

热点推荐