?
Solved

Sending A Custom Header

Posted on 2008-10-09
3
Medium Priority
?
1,022 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 2000 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

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

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

Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
Simulator games are perfect for generating sample realistic data streams, especially for learning data analysis. It is even useful for demoing offerings such as Azure stream analytics, PowerBI etc.
In a question here at Experts Exchange (https://www.experts-exchange.com/questions/29062564/Adobe-acrobat-reader-DC.html), a member asked how to create a signature in Adobe Acrobat Reader DC (the free Reader product, not the paid, full Acrobat produ…
Is your OST file inaccessible, Need to transfer OST file from one computer to another? Want to convert OST file to PST? If the answer to any of the above question is yes, then look no further. With the help of Stellar OST to PST Converter, you can e…
Suggested Courses

850 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