我想设置的HttpWebRequest头的引荐参数的值,但它给无差错C#:HttpWebRequest的
功能,我使用(C#):
webRequest.Headers.Set(HttpRequestHeader.Referer, "http://www.microsoft.com");
错误:
Invalid parameters. A required parameter is not found or contains invalid value.
我想设置的HttpWebRequest头的引荐参数的值,但它给无差错C#:HttpWebRequest的
功能,我使用(C#):
webRequest.Headers.Set(HttpRequestHeader.Referer, "http://www.microsoft.com");
错误:
Invalid parameters. A required parameter is not found or contains invalid value.
从MSDN试用此方法如果您发布您的代码,我可以更好地帮助您。
HttpWebRequest myHttpWebRequest=(HttpWebRequest)WebRequest.Create(myUri);
// Set referer property to http://www.microsoft.com .
myHttpWebRequest.Referer="http://www.microsoft.com";
// Assign the response object of 'HttpWebRequest' to a 'HttpWebResponse' variable.
HttpWebResponse myHttpWebResponse=(HttpWebResponse)myHttpWebRequest.GetResponse();
// Display the contents of the page to the console.
Stream streamResponse=myHttpWebResponse.GetResponseStream();
StreamReader streamRead = new StreamReader(streamResponse);
Char[] readBuffer = new Char[256];
int count = streamRead.Read(readBuffer, 0, 256);
Console.WriteLine("\nThe contents of HTML page are.......");
while (count > 0)
{
String outputData = new String(readBuffer, 0, count);
Console.Write(outputData);
count = streamRead.Read(readBuffer, 0, 256);
}
Console.WriteLine("\nHTTP Request Headers :\n\n{0}",myHttpWebRequest.Headers);
Console.WriteLine("\nHTTP Response Headers :\n\n{0}",myHttpWebResponse.Headers);
streamRead.Close();
streamResponse.Close();
// Release the response object resources.
myHttpWebResponse.Close();
Console.WriteLine("Referer to the site is:{0}",myHttpWebRequest.Referer);
有你无法通过webRequest.Headers.Set
的Referer是他们中的一个设置一些保留HTTP头。
对于这些总是有一个特殊的属性来设置。
在你的情况下webRequest.Referer = "http://google.com"
会做。
@kedar kamthe,你不能把HttpRequestHeader.Referer在那里,因为那是期待值,我相信,但不知道......我想你想用这样的:
webRequest.Headers .Set(“Referer”,“http://www.microsoft.com”);
但你应该把它当作Chris Ballance的例子。这应该有效,但如果这不起作用,就试试我上面展示的;)。
你应该把你的代码放在这里,所以我们可以看到什么是错的。
这里是典型用途:
HttpWebRequest req = (HttpWebRequest)WebRequest.Create("");
req.Referer = "http://www.google.com";
显示你的代码。
请给我看看代码。 – 2009-02-22 18:46:14