473,804 Members | 3,349 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

webrequest session

use HttpWebrequest.

get cookie in URL1
and use this cookie in URL2

how to coding?
Nov 15 '05 #1
1 6442
¼*°*È£ wrote:
use HttpWebrequest.

get cookie in URL1
and use this cookie in URL2

how to coding?


Here's a very basic smaple method that demonstrates how to use cookies:

void TestCookie(stri ng url) {
HttpWebRequest firstRequest = (HttpWebRequest ) WebRequest.Crea te(url);
firstRequest.Co okieContainer = new CookieContainer ();
HttpWebResponse firstResponse = (HttpWebRespons e)
firstRequest.Ge tResponse();

HttpWebRequest secondRequest = (HttpWebRequest ) WebRequest.Crea te(url);
secondRequest.C ookieContainer = new CookieContainer ();
CookieCollectio n cookies = firstResponse.C ookies;
secondRequest.C ookieContainer. Add(cookies);

HttpWebResponse secondResponse = (HttpWebRespons e)
secondRequest.G etResponse();

Console.WriteLi ne("Done.");
}

Cheers,

--
Joerg Jooss
jo*********@gmx .net

Nov 15 '05 #2

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

Similar topics

0
1283
by: omyek | last post by:
I'm essentially trying to do what a lot of users seem to want when using the above classes, and that's POST to a webpage. Well, I'm golden when it comes to POSTing, I've been able to post to websites using both the webrequest/response and webclient methods. However, the problem I'm running into with both options is I seem to "lose" my connection/session. Let me try to explain a little better. I connect to a website which
1
2310
by: Ron | last post by:
Hi there, I'm trying to 'browse' a website using the HttpWebRequest class by calling the following function (webRequest is declared outside the function): private string GetHtml(string sUrl) { string sResult; WebResponse objResponse; webRequest = (HttpWebRequest)WebRequest.Create(sUrl);
4
4325
by: Paul | last post by:
Hello, I tried to execute a button on an aspx webpage using WebRequest, but it failed. When posting data as if I did a login (see code), I just receive the login page, instead of the page I should get after login. The button I tried to 'push' (by adding &login=Login in de posted data, where login is the name of the login button - I verified this data by capturing the data of a request using a webbrowser) has not executed.
3
6352
by: Paul | last post by:
Hello, First I want to refer to the problem "WebRequest : execute a button" of a few days ago. The way I solved it, I loose my session, and as a consequence my session variables. I don't want to keep those variables, as an alternative, as ViewState variables because I don't want to transfer to many hidden fields. This is the code I use :
3
5109
by: Mario | last post by:
Greetings! Here is the problem i'm facing. I'm supposed to read some user input on Page1, then, depends on what the user inputs, redirect him to Page2 or Page3 and send the entered data with it. Page2 or Page3 will then do some user verification and depending on success/failure redirect again to Page1(failure) or Page4(success) So far i managed to implement sending the data with webrequest, but the problem comes with redirection.
1
8207
by: Mr Flibble | last post by:
OK I logon to a web site and I manage to get an SMSESSION cookie that I then store in a variable called _session (a class scoping variable). I do this by calling a logon URL and setting a cookie to SMCHALLANGE=YES to allow me to obtain a session. I then iterate the cookie collection to extract the SMSESSION value. All is good (so far). This is when the sky turns grey and the rain starts to fall. I then use this SMSESSION in a web...
6
1717
by: matt | last post by:
hello, i am having trouble doing something. when a user triggers a certain event in my app, i need to initiate another web request to one of my other webpages, programmatically. currently, i do this via a WebRequest -- i attach the default credentials and get the response stream. that part works. like so: WebRequest request = HttpWebRequest.Create(reportAspxURL); request.Credentials = CredentialCache.DefaultCredentials;
6
10012
by: Jack | last post by:
I have a WebRequest object that I use to log into a site and then post some XML. In doing this I set the KeepAlive = true so that it maintains the connection and does operates undo the initial login. Is there a way to force this connection to close after I an done with it. What happens is that I may need to post the XML in several chunks due to size therefore I cannot set the KeepAlive to False when I post the XML and the way the code...
3
8189
by: Dave | last post by:
string m_request = some_web_page; HttpWebRequest request = (HttpWebRequest)WebRequest.Create(m_request ); HttpWebResponse response = (HttpWebResponse)request.GetResponse(); Which works fine, but I need to set and send a cookie with the WebRequest. How do I do that?
3
8839
by: ThatsIT.net.au | last post by:
I am making a console app that requests pages from our site one after another. Each request starts a new session, What I want to do is make all requests in the same session. How can I do this. I was hoping to be able to get the session back from first request and then set them on each further request. Any ideas?
0
9705
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9576
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
10567
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
10323
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10310
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10074
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
5515
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
5647
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3809
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.