0

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.
1
  • Please show me the code. Commented Feb 22, 2009 at 18:46

4 Answers 4

4

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); 
Sign up to request clarification or add additional context in comments.

Comments

4

Here is typical use:

HttpWebRequest req = (HttpWebRequest)WebRequest.Create("");
req.Referer = "http://www.google.com";

Show your code.

Comments

1

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.

Comments

0

@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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.