http请求头设置问题
各位,以下是php的一段代码function _fetchUrl($url)
{
//初始化 curl
$ch = curl_init();
curl_setopt($ch,CURLOPT_URL,$url);
curl_setopt($ch,CURLOPT_REFERER,"");
curl_setopt($ch,CURLOPT_SSL_VERIFYPEER,0);
curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch,CURLOPT_FOLLOWLOCATION,1);
$html = curl_exec($ch);
curl_close($ch);
return $html;
}
我如何在asp.net中设置CURLOPT_SSL_VERIFYPEER,CURLOPT_RETURNTRANSFER,CURLOPT_FOLLOWLOCATION这些参数。 --------------------编程问答-------------------- 谁来帮个忙。。。 --------------------编程问答-------------------- 不知道,没用过 --------------------编程问答-------------------- Request Header只有在发送请求的时候才需要设置的,你需要在asp.net中给别的地方发送请求? --------------------编程问答--------------------
using System;
using System.Net;
class Program
{
static void Main()
{
// Create web client.
WebClient client = new WebClient();
// Set user agent and also accept-encoding headers.
client.Headers["User-Agent"] = "Googlebot/2.1 (+http://www.googlebot.com/bot.html)";
client.Headers["Accept-Encoding"] = "gzip";
// Download data.
byte[] arr = client.DownloadData("http://www.dotnetperls.com/");
// Get response header.
string contentEncoding = client.ResponseHeaders["Content-Encoding"];
// Write values.
Console.WriteLine("--- WebClient result ---");
Console.WriteLine(arr.Length);
Console.WriteLine(contentEncoding);
}
}
参考
http://www.dotnetperls.com/webclient --------------------编程问答-------------------- 或者用HttpWebRequest
byte[] buffer = Encoding.ASCII.GetBytes("fareId=123456"); //the data you want to send to the web service
HttpWebRequest WebReq = (HttpWebRequest)WebRequest.Create(url);
WebReq.Method = "POST";
WebReq.ContentType = "application/x-www-form-urlencoded";
WebReq.ContentLength = buffer.Length;
WebReq.Headers["Cookie"] = "JSESSIONID=4567845226" --------------------编程问答-------------------- 我是要设置CURLOPT_SSL_VERIFYPEER,CURLOPT_RETURNTRANSFER,CURLOPT_FOLLOWLOCATION这几个选项,谁知道?
补充:.NET技术 , ASP.NET