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基金的接口,懂得能和我说说能成不网络编程无法按照请求设置空的或空白的方法接口
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货