首页 > 编程 > .NET > 正文

ASP.NET GET 方式提交数据!

2024-07-10 12:57:15
字体:
来源:转载
供稿:网友
private string requestget(string theurl, string theproxy)
{
uri uri = new uri(theurl);
httpwebrequest request = (httpwebrequest) webrequest.create(uri);
string page;
try
{

request.keepalive = false;
request.protocolversion=httpversion.version10;

request.method = "get";

request.contenttype = "application/x-www-form-urlencoded";

request.proxy = system.net.webproxy.getdefaultproxy();

//allow auto redirects from redirect headers
request.allowautoredirect=true;

//maximum of 10 auto redirects
request.maximumautomaticredirections=10;

//30 second timeout for request
request.timeout=(int) new timespan(0,0,60).totalmilliseconds;

//give the crawler a name.
request.useragent = "mozilla/4.0 (compatible; msie 6.0; windows nt 5.1)";
//request.useragent="mozilla/3.0 (compatible; my browser/1.0)";

httpwebresponse response = (httpwebresponse) request.getresponse();
stream responsestream = response.getresponsestream();
streamreader readstream = new streamreader (responsestream, system.text.encoding.default);

page = readstream.readtoend();
}
catch (exception ee)
{
page = "fail message : "+ee.message;
}
return page;

}



发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表