日期:2014-05-18  浏览次数:21145 次

关于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方式发送就好了。