首页新闻找找看学习计划

HTTPWEBREQUEST 操作超时很费解

0
[待解决问题]

我在模拟请求[POST]一个网站的时候,一直连接不上去,总是提示我”操作超时“

  HttpWebRequest httpWebRequest = null;
            HttpWebResponse httpWebResponse = null;
            try
            {
                byte[] byteRequest = Encoding.Default.GetBytes(postData);//格式化POST数据
 
                httpWebRequest = (HttpWebRequest)HttpWebRequest.Create(url);//发送请求
               // httpWebRequest.CookieContainer = cookieContainer;//填充COOKIE
                //httpWebRequest.ContentType = "application/x-www-form-urlencoded";
                //httpWebRequest.ServicePoint.ConnectionLimit = maxTry;
               ;
                //httpWebRequest.Headers.Add("Accept-Language", "ko,zh-cn;q=0.5");
                //httpWebRequest.Headers.Add("Accept-Encoding", "gzip, deflate");
 
               // httpWebRequest.Referer = "";
 
                //httpWebRequest.Accept = "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8";
                //httpWebRequest.UserAgent = "Mozilla/5.0 (Windows NT 6.1; rv:20.0) Gecko/20100101 Firefox/20.0";
                httpWebRequest.Method = isPost ? "POST" : "GET";//那种请求?
                httpWebRequest.ContentLength = byteRequest.Length;//获取数据包大小
 
                Stream stream = httpWebRequest.GetRequestStream();//获取流对象
                stream.Write(byteRequest, 0, byteRequest.Length);
                stream.Close();
 
                httpWebResponse = (HttpWebResponse)httpWebRequest.GetResponse();
                //定义数据响应信息
                Stream responseStream = httpWebResponse.GetResponseStream();//获取服务端回发达留信息
 
                StreamReader streamReader = new StreamReader(responseStream, encoding);
 
                string html = streamReader.ReadToEnd();
                streamReader.Close();
                responseStream.Close();
                currentTry = 0;
 
                httpWebRequest.Abort();
                httpWebResponse.Close();
 
                return html;//获取 
            }
            catch (System.Net.WebException e)
            {

 

 


                Stream stream = httpWebRequest.GetRequestStream();/这句就出问题了
代码片段。HEAD头没问题,我用第三方 POSET模拟软件(HTTPAnalyzerFullV自带)提交的时候HEDA头什么也不设置值提交返回正 常(也就是说提交的时候只有一个POST地址。和一个HOST主机属性,)而我用HTTPWEBREQUEST却怎么也访问不了
我抓POST模拟器(HTTPAnalyzerFullV自带)返回的包的时候发现返回头信息有

Expires -1 这个标识 难道跟这个有关系?如果有关系HTTPWEQUEREST 应该怎么设置。呢

mcxiao的主页 mcxiao | 初学一级 | 园豆:18
提问于:2013-04-21 16:00
< >
分享
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册