首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > .NET > C# >

关于HttpWebRequest和HttpWebResponse使用的端口,该如何处理

2012-01-15 
关于HttpWebRequest和HttpWebResponse使用的端口我用request(HttpWebRequest)HttpWebRequest.Create(strU

关于HttpWebRequest和HttpWebResponse使用的端口
我用
request   =(HttpWebRequest)HttpWebRequest.Create(strUrl);
request.AllowAutoRedirect   =   false;
request.UserAgent   =   "Mozilla/4.0   (compatible;   MSIE   6.01;   Windows   NT   5.0) ";
request.ContentType   =   "application/x-www-form-urlencoded ";//作为表单请求
request.Method   =   "POST ";
request.ContentLength   =   B.Length;
发送请求

response   =   (HttpWebResponse)request.GetResponse();
System.IO.StreamReader   sr   =   new   System.IO.StreamReader(response.GetResponseStream(),   System.Text.Encoding.GetEncoding( "GB2312 "));
接收数据,现在在电脑上用ie可以访问网页,但是用上面的代码不行。现在网络上有防火墙,请问需要开什么端口?80不行吗?

[解决办法]
用了代理服务器ISA之类的东东没
[解决办法]
需要把Post的数据也传上去的吧,你那个B.Length是什么?可以参考以下代码。
string param = "text=abc&value=cde ";
byte[] postData = Encoding.ASCII.GetBytes(param);
request.ContentLength = postData.Length;
Stream requestStream = request.GetRequestStream();
requestStream.Write(postData, 0, postData.Length);
requestStream.Close();

如果没有需要发送的数据,直接用GET方式发送就好了。

热点排行