Reputation: 8178
I am trying to set value of referer parameter of httpwebrequest header, but it is giving error-
Function that I am using (C#):
webRequest.Headers.Set(HttpRequestHeader.Referer, "http://www.microsoft.com");
Error:
Invalid parameters. A required parameter is not found or contains invalid value.
Upvotes: 0
Views: 6273
Reputation: 27265
There are some reserved HTTP Headers which you can't set via webRequest.Headers.Set
Referer is one of them.
For these there is always a special property to set.
In your case webRequest.Referer = "http://google.com"
will do.
Upvotes: 1
Reputation: 5090
Here is typical use:
HttpWebRequest req = (HttpWebRequest)WebRequest.Create("");
req.Referer = "http://www.google.com";
Show your code.
Upvotes: 4
Reputation: 34337
Try this method from MSDN If you post your code I can better help you out.
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);
Upvotes: 4
Reputation: 2720
@kedar kamthe, you can't put HttpRequestHeader.Referer in there, because that is expecting a value, I believe, but not sure... I think you wanted to use this:
webRequest.Headers.Set("Referer", "http://www.microsoft.com");
But you should use it as Chris Ballance's example. That should work, but if that doesn't work, just try as I show above ;).
You should put your code here, so we can see what is wrong.
Upvotes: 0