Solved

Sending A Custom Header

Posted on 2008-10-09
3
1,008 Views
Last Modified: 2013-11-08
Hello, I need to send a custom header to the requesting host but its my first time attempting this and I cant get it to work.

Im sending the Custom header using this:
                    HttpContext.Current.Response.ContentType = "image/jpeg"
                    HttpContext.Current.Response.Headers.Add("image-status", "1")
                    outputImage.Save(HttpContext.Current.Response.OutputStream, JPEGCodec, EncParams)
                    HttpContext.Current.Response.Flush()
                    HttpContext.Current.Response.Close()

And in my test page I have:
        Dim URL_Object As New System.Uri("http://website.com")
        Dim URL_WebRequest As System.Net.HttpWebRequest
        Dim URL_WebResponse As System.Net.HttpWebResponse
        URL_WebRequest = System.Net.WebRequest.Create(URL_Object)
        URL_WebRequest.Timeout = 20000
        URL_WebResponse = URL_WebRequest.GetResponse
        For Each Header As String In URL_WebResponse.Headers
            Response.Write(URL_WebResponse.Headers.Item(Header).ToString)
        Next

But my custom header is not contained in the response when I write out all the header items to the browser.
I also tried:
HttpContext.Current.Response.AppendHeader("image-status", "1")
What am i doing wrong?

Thanks!
0
Comment
Question by:grogo21
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 8

Expert Comment

by:rlh68
ID: 22683455

Download and install fiddler, it is a free application that will allow you to see all traffic between your browser and the web server. Headers, cookies, source, etc.

http://www.fiddlertool.com/fiddler/

With fiddler running, navigate your page a few times to see what headers are being passed.
0
 

Author Comment

by:grogo21
ID: 22683545
Hello,
Fiddler shows that the custom headers are there.  But how can I access their values.  Using the following line:
        Response.Write(URL_WebResponse.Headers.Item("snapshot-status").ToString)
I get error Object reference not set to an instance of an object.

Thanks
Untitled-1.jpg
0
 
LVL 8

Accepted Solution

by:
rlh68 earned 500 total points
ID: 22684127

Change your For...Each statement to the below and see what you get.

  For Each key As String In URL_WebResponse.Headers.Keys
       Dim value As String = URL_WebResponse.Headers.Item(key)
       Response.Write(key & " : " & value & "<br />")
   Next

' may be add this line too.

 Response.Write("My Field = " & URL_WebResponse.Headers.Item("image-status") & "<br />")
0

Featured Post

Revamp Your Training Process

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …

695 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question