472,791 Members | 1,878 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,791 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 9185
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: erikbower65 | last post by:
Using CodiumAI's pr-agent is simple and powerful. Follow these steps: 1. Install CodiumAI CLI: Ensure Node.js is installed, then run 'npm install -g codiumai' in the terminal. 2. Connect to...
0
linyimin
by: linyimin | last post by:
Spring Startup Analyzer generates an interactive Spring application startup report that lets you understand what contributes to the application startup time and helps to optimize it. Support for...
0
by: erikbower65 | last post by:
Here's a concise step-by-step guide for manually installing IntelliJ IDEA: 1. Download: Visit the official JetBrains website and download the IntelliJ IDEA Community or Ultimate edition based on...
0
by: kcodez | last post by:
As a H5 game development enthusiast, I recently wrote a very interesting little game - Toy Claw ((http://claw.kjeek.com/))。Here I will summarize and share the development experience here, and hope it...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Sept 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
by: Taofi | last post by:
I try to insert a new record but the error message says the number of query names and destination fields are not the same This are my field names ID, Budgeted, Actual, Status and Differences ...
5
by: DJRhino | last post by:
Private Sub CboDrawingID_BeforeUpdate(Cancel As Integer) If = 310029923 Or 310030138 Or 310030152 Or 310030346 Or 310030348 Or _ 310030356 Or 310030359 Or 310030362 Or...
0
by: lllomh | last post by:
How does React native implement an English player?
0
by: Mushico | last post by:
How to calculate date of retirement from date of birth

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.