Solved

Sending A Custom Header

Posted on 2008-10-09
3
973 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
  • 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

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

758 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now