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

winform里面怎么发送get请求,求高手
我只需要发送请求,做的操作就相当于到浏览器里面打开一个url一样的操作,但是我不需要打开页面,只需要发送请求就行了,求指点,winform里面是没有Response.Redirect(url)的

------解决方案--------------------
用HttpWebRequest.GetResponse方法

HttpWebRequest request = (HttpWebRequest)WebRequest.Create (url);

// Set some reasonable limits on resources used by this request
request.MaximumAutomaticRedirections = 4;
request.MaximumResponseHeadersLength = 4;
// Set credentials to use for this request.
request.Credentials = CredentialCache.DefaultCredentials;
HttpWebResponse response = (HttpWebResponse)request.GetResponse ();


------解决方案--------------------
不过你要自己解释HttpWebResponse 里的内容,HttpWebResponse是服务器返回客户端的信息,你要自己Redirect,
------解决方案--------------------
System.Net.WebRequest request = (WebRequest)WebRequest.Create(strUrl);

request.Timeout = 25000;

WebResponse response = (WebResponse)request.GetResponse();

ResponseInfo rinfo = PayStringInterface.VoucherResponse(response.GetResponseStream());