Solved

Sending A Custom Header

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

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

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

Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
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…
In a recent question (https://www.experts-exchange.com/questions/28997919/Pagination-in-Adobe-Acrobat.html) here at Experts Exchange, a member asked how to add page numbers to a PDF file using Adobe Acrobat XI Pro. This short video Micro Tutorial sh…
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…

773 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