0

I have to add HTTP_MSDN in header so that whenever I will click on button this HTTP_MSDN should be visible for this url. Please help me.

protected void Page_Load(object sender, EventArgs e)
{
    HttpWebRequest request = (HttpWebRequest)WebRequest.Create("url");
    //HttpWebRequest req = WebRequest.Create("http://wap.mobiletashan.com") as HttpWebRequest;
    HttpWebResponse response = (HttpWebResponse)request.GetResponse();
    request.Headers.Add("HTTP_MSDN", "0123456789");                      
}
protected void Button1_Click(object sender, EventArgs e)
{
    NameValueCollection coll;
    coll = Request.ServerVariables;
    String[] arr1 = coll.AllKeys;
    String[] arr2 = coll.GetValues(arr1[0]);
    Response.Write(Server.HtmlEncode(arr2[0]));
}
1
  • I want when I click on button whatever header I have added it should be visible. Commented Apr 7, 2014 at 11:03

1 Answer 1

2

If you need to add your header to request, add it before getting response, like this:

HttpWebRequest request = (HttpWebRequest)WebRequest.Create("url");
request.Headers.Add("HTTP_MSDN", "0123456789"); 
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
Sign up to request clarification or add additional context in comments.

3 Comments

I have add it but When I click on button HTTP_MSDN header is not showing. Please share update...
Some misunderstanding... Do you want to add your header to you page when clickin on button?
I want to add this header request.Headers.Add("HTTP_MSDN", "0123456789") dueing page load. Also I want get this header along with all headers get by request.servervariables("ALL_HTTP") on button click

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.