473,395 Members | 1,679 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Add the headers to httpwebrequest/httpwebresponse from .net code

how to add the headers to httpwebrequest/httpwebresponse from .net code ?
Jul 21 '05 #1
4 9242
Vivek <Vi***@discussions.microsoft.com> wrote:
how to add the headers to httpwebrequest/httpwebresponse from .net code ?


Use WebRequest.Create as normal, cast it to HttpWebRequest, and use the
Headers property.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Jul 21 '05 #2


"Jon Skeet [C# MVP]" wrote:
Vivek <Vi***@discussions.microsoft.com> wrote:
how to add the headers to httpwebrequest/httpwebresponse from .net code ?


Use WebRequest.Create as normal, cast it to HttpWebRequest, and use the
Headers property.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too

thanks Jon
can you send me the code?
Jul 21 '05 #3
Ok, let me re-phrase the question here, this is what needs done:

We need to create an asp.net application, which validates a user and on
success transfers/redirects the user to another asp.net application after
adding a custom header to the request stream eg. ValidatedUserName.

When we add header to current request object and then redirect using
server.transfer() we don't get this header on the target aspx page (yes, we
tried after setting the preserve headers to true), what we think the cause
can be is that when server.transfer is called it creates a new request to the
target server and the headers that we added in the current request are not
available in that request.

We also tried adding headers in request and then getting the response after
creating a WebResponse object via WebRequest.Create(<url>) (this time it was
just a test to see if the headers were actually added when the request was
created, not redirecting as actually needed) and viola we got the header in
the target application (but this didn't helped much as what we need is a
redirect with header).

Please advice how can we do a redirect to a different webapplication by
adding custom header in request stream (there has to be a overwrite
somewhere, so that we can do what we need here).

Thanks!

"Jon Skeet [C# MVP]" wrote:
Vivek <Vi***@discussions.microsoft.com> wrote:
how to add the headers to httpwebrequest/httpwebresponse from .net code ?


Use WebRequest.Create as normal, cast it to HttpWebRequest, and use the
Headers property.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too

Jul 21 '05 #4
Vivek <Vi***@discussions.microsoft.com> wrote:
Ok, let me re-phrase the question here, this is what needs done:

We need to create an asp.net application, which validates a user and on
success transfers/redirects the user to another asp.net application after
adding a custom header to the request stream eg. ValidatedUserName.

When we add header to current request object and then redirect using
server.transfer() we don't get this header on the target aspx page (yes, we
tried after setting the preserve headers to true), what we think the cause
can be is that when server.transfer is called it creates a new request to the
target server and the headers that we added in the current request are not
available in that request.

We also tried adding headers in request and then getting the response after
creating a WebResponse object via WebRequest.Create(<url>) (this time it was
just a test to see if the headers were actually added when the request was
created, not redirecting as actually needed) and viola we got the header in
the target application (but this didn't helped much as what we need is a
redirect with header).

Please advice how can we do a redirect to a different webapplication by
adding custom header in request stream (there has to be a overwrite
somewhere, so that we can do what we need here).


If you're looking at the same method I am, there isn't a method which
has a "preserve headers" - only "preserve form" which is somewhat
different.

I'm afraid I'm far from an ASP.NET expert - I suggest you ask on the
ASP.NET newsgroup.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Jul 21 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

9
by: Mike Cronin via DotNetMonster.com | last post by:
Hi there, Can anyone tell me what level of encryption is used when making an HTTPS POST request through an instance of the System.Net.HttpWebRequest object? Thanks much in advance! Mike...
2
by: Dunc | last post by:
Hi, I'm using a c# app to download zipped XML data from a 3rd party. All is good, but the XML is generated on the remote machine at the time of request (hence the huge timeout), and when it...
3
by: Vivek | last post by:
how to add the headers to httpwebrequest/httpwebresponse from .net code ?
6
by: James MA | last post by:
I'm now writing a small program to communicate a web server to simulate a web client. I use te httpwebrequest to talk with the server, and it works find for "POST" method, however, when i test...
5
by: rlueneberg | last post by:
I am totally confused. Can someone please illuminate what is going on under the hood in this piece of code from John Lewis. My main confusion is how the cookieContainer can be passed to the...
0
by: Piotrekk | last post by:
Hi I have the following code: request = (HttpWebRequest)WebRequest.Create(FullPath); request.ProtocolVersion = HttpVersion.Version11; response = (HttpWebResponse)request.GetResponse();
1
by: ALA | last post by:
Hi, does anybody know if it is possible to pass the SessionID with a web request by using a cookie so that the invoked page in the same domain can access the session objects of the current user?...
5
by: piedpiper | last post by:
I am coding a http proxy in c# and using httpwebrequest class to send request to the web server, when the server returns multiple set-cookie headers then the httpwebresponse object combines them all...
15
by: Nightcrawler | last post by:
I am currently using the HttpWebRequest and HttpWebResponse to pull webpages down from a few urls. string url = "some url"; HttpWebRequest httpWebRequest =...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.