Solved

Sending A Custom Header

Posted on 2008-10-09
3
1,006 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

Salesforce Has Never Been Easier

Improve and reinforce salesforce training & adoption using WalkMe's digital adoption platform. Start saving on costly employee training by creating fast intuitive Walk-Thrus for Salesforce. Claim your Free Account Now

Question has a verified solution.

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

User art_snob (http://www.experts-exchange.com/M_6114203.html) encountered strange behavior of Android Web browser on his Mobile Web site. It took a while to find the true cause. It happens so, that the Android Web browser (at least up to OS ver. 2.…
The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (http://www.ecb.europa.eu/stats/exch…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…
Finding and deleting duplicate (picture) files can be a time consuming task. My wife and I, our three kids and their families all share one dilemma: Managing our pictures. Between desktops, laptops, phones, tablets, and cameras; over the last decade…

732 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