473,669 Members | 2,526 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 9256
Vivek <Vi***@discussi ons.microsoft.c om> wrote:
how to add the headers to httpwebrequest/httpwebresponse from .net code ?


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

--
Jon Skeet - <sk***@pobox.co m>
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***@discussi ons.microsoft.c om> wrote:
how to add the headers to httpwebrequest/httpwebresponse from .net code ?


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

--
Jon Skeet - <sk***@pobox.co m>
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. ValidatedUserNa me.

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.Crea te(<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***@discussi ons.microsoft.c om> wrote:
how to add the headers to httpwebrequest/httpwebresponse from .net code ?


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

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

Jul 21 '05 #4
Vivek <Vi***@discussi ons.microsoft.c om> 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. ValidatedUserNa me.

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.Crea te(<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.co m>
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
8177
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 Cronin Data On Call - Programmer
2
17120
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 sends me the file, it has an error message appended to the beginning: ÿþ<br /> <b>Warning</b>: HTTP_USER_AGENT variable is not set, cannot determine user agent name in <b>/home/sites/site2/web/check_auth.inc.php</b> on line
3
362
by: Vivek | last post by:
how to add the headers to httpwebrequest/httpwebresponse from .net code ?
6
8746
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 other link using "GET" method, i found that the cookies data has not included in the request. Here is the sample: ' sURL is the URL of server page ' pCookies is a varible contain the cookies data
5
35277
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 subsequent request if it is not assigned anywhere? So far this is what I understand: -Creates New cookieContainer CookieContainer cookieContainer = new CookieContainer();
0
1195
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
5656
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? HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url); request.CookieContainer = new CookieContainer(); HttpCookie sessionCookie = HttpContext.Current.Request.Cookies;
5
10855
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 in to a single set-cookie key-value pair. I am tryin to get the value of the headers in the following way. for (int i = 0; i < response.Headers.Count; ++i) Console.WriteLine("{0}:{1}", response.Headers.Keys, response.Headers);
15
3085
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 = (HttpWebRequest)WebRequest.Create(url); using (HttpWebResponse httpWebResponse = (HttpWebResponse)httpWebRequest.GetResponse()) {
0
8384
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8896
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8659
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7410
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5683
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4208
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4387
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2798
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2035
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.