How to Maintain Session Variables using WebRequest .
-
I am using WebRequest to Get the HTML of specific URL(of same application) which works fine but not the session variables are not being sent. If any one has used this please let me know?:zzz:
-
I am using WebRequest to Get the HTML of specific URL(of same application) which works fine but not the session variables are not being sent. If any one has used this please let me know?:zzz:
Are you using HttpRequest to get HTML page ?
Thanks and Regards Sandeep If If you look at what you do not have in life, you don't have anything, If you look at what you have in life, you have everything... "
-
Are you using HttpRequest to get HTML page ?
Thanks and Regards Sandeep If If you look at what you do not have in life, you don't have anything, If you look at what you have in life, you have everything... "
I am using WebRequest and here is the code:
Dim _WebReq As WebRequest Dim _WebResp As WebResponse Dim _StreamReader As StreamReader Dim strHTML As String _WebReq = _WebReq.Create(strURL) _WebResp = _WebReq.GetResponse _StreamReader = New StreamReader(_WebResp.GetResponseStream) GetHTMLStream = _StreamReader.ReadToEnd
Thanks -
I am using WebRequest and here is the code:
Dim _WebReq As WebRequest Dim _WebResp As WebResponse Dim _StreamReader As StreamReader Dim strHTML As String _WebReq = _WebReq.Create(strURL) _WebResp = _WebReq.GetResponse _StreamReader = New StreamReader(_WebResp.GetResponseStream) GetHTMLStream = _StreamReader.ReadToEnd
ThanksWhy don't you use Http Web Request using that u can set and get cookies also
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(args[0]); request.CookieContainer = new CookieContainer(); HttpWebResponse response = (HttpWebResponse) request.GetResponse(); // Print the properties of each cookie. foreach (Cookie cook in response.Cookies) { Console.WriteLine("Cookie:"); Console.WriteLine("{0} = {1}", cook.Name, cook.Value); Console.WriteLine("Domain: {0}", cook.Domain); Console.WriteLine("Path: {0}", cook.Path); Console.WriteLine("Port: {0}", cook.Port); Console.WriteLine("Secure: {0}", cook.Secure); Console.WriteLine("When issued: {0}", cook.TimeStamp); Console.WriteLine("Expires: {0} (expired? {1})", cook.Expires, cook.Expired); Console.WriteLine("Don't save: {0}", cook.Discard); Console.WriteLine("Comment: {0}", cook.Comment); Console.WriteLine("Uri for comments: {0}", cook.CommentUri); Console.WriteLine("Version: RFC {0}" , cook.Version == 1 ? "2109" : "2965"); // Show the string representation of the cookie. Console.WriteLine ("String: {0}", cook.ToString()); }
Thanks and Regards Sandeep If If you look at what you do not have in life, you don't have anything, If you look at what you have in life, you have everything... "
-
Why don't you use Http Web Request using that u can set and get cookies also
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(args[0]); request.CookieContainer = new CookieContainer(); HttpWebResponse response = (HttpWebResponse) request.GetResponse(); // Print the properties of each cookie. foreach (Cookie cook in response.Cookies) { Console.WriteLine("Cookie:"); Console.WriteLine("{0} = {1}", cook.Name, cook.Value); Console.WriteLine("Domain: {0}", cook.Domain); Console.WriteLine("Path: {0}", cook.Path); Console.WriteLine("Port: {0}", cook.Port); Console.WriteLine("Secure: {0}", cook.Secure); Console.WriteLine("When issued: {0}", cook.TimeStamp); Console.WriteLine("Expires: {0} (expired? {1})", cook.Expires, cook.Expired); Console.WriteLine("Don't save: {0}", cook.Discard); Console.WriteLine("Comment: {0}", cook.Comment); Console.WriteLine("Uri for comments: {0}", cook.CommentUri); Console.WriteLine("Version: RFC {0}" , cook.Version == 1 ? "2109" : "2965"); // Show the string representation of the cookie. Console.WriteLine ("String: {0}", cook.ToString()); }
Thanks and Regards Sandeep If If you look at what you do not have in life, you don't have anything, If you look at what you have in life, you have everything... "
Please look into this code is there any mistake in it? i am not being able to get session values?
Dim _HttpWebRequest As HttpWebRequest = HttpWebRequest.Create(strURL) _HttpWebRequest.CookieContainer = New CookieContainer Dim _HttpWebResponse As HttpWebResponse _HttpWebResponse = _HttpWebRequest.GetResponse Dim _Cookie As Cookie For Each _Cookie In _HttpWebResponse.Cookies _HttpWebRequest.CookieContainer.Add(_Cookie) Next Dim _StreamReader As StreamReader ' Process the URL and Get HTML _StreamReader = New StreamReader(_HttpWebResponse.GetResponseStream) GetHTMLStream = _StreamReader.ReadToEnd
-
Please look into this code is there any mistake in it? i am not being able to get session values?
Dim _HttpWebRequest As HttpWebRequest = HttpWebRequest.Create(strURL) _HttpWebRequest.CookieContainer = New CookieContainer Dim _HttpWebResponse As HttpWebResponse _HttpWebResponse = _HttpWebRequest.GetResponse Dim _Cookie As Cookie For Each _Cookie In _HttpWebResponse.Cookies _HttpWebRequest.CookieContainer.Add(_Cookie) Next Dim _StreamReader As StreamReader ' Process the URL and Get HTML _StreamReader = New StreamReader(_HttpWebResponse.GetResponseStream) GetHTMLStream = _StreamReader.ReadToEnd
M Javed Khan wrote:
Dim _Cookie As Cookie For Each _Cookie In _HttpWebResponse.Cookies _HttpWebRequest.CookieContainer.Add(_Cookie) Next
Here you are adding the cookie
Thanks and Regards Sandeep If If you look at what you do not have in life, you don't have anything, If you look at what you have in life, you have everything... "
-
M Javed Khan wrote:
Dim _Cookie As Cookie For Each _Cookie In _HttpWebResponse.Cookies _HttpWebRequest.CookieContainer.Add(_Cookie) Next
Here you are adding the cookie
Thanks and Regards Sandeep If If you look at what you do not have in life, you don't have anything, If you look at what you have in life, you have everything... "
I have removed this but still session values are not being used by HTTPWebRequest :(.
-
I have removed this but still session values are not being used by HTTPWebRequest :(.
I am still asking you what you want to do ? As session varaibles are store at the server side you can't get them using response .. How can you read the session varaibles ? You can read cookies are those are store at the client side
Thanks and Regards Sandeep If If you look at what you do not have in life, you don't have anything, If you look at what you have in life, you have everything... "
-
I am still asking you what you want to do ? As session varaibles are store at the server side you can't get them using response .. How can you read the session varaibles ? You can read cookies are those are store at the client side
Thanks and Regards Sandeep If If you look at what you do not have in life, you don't have anything, If you look at what you have in life, you have everything... "
Sorry for confussion!!! let me explain it to u! Let suppose i have URL = "http://www.some.com" Now in it i have a Grid which depends on some session variables. Now when i use Response.Redirect(URL) the grid reterives the data on the basis of session variables. but when i use HTTPWebRequest to get the HTML which is generated for that URL grid doesn't reterives session values. I have to get the execute the URL on the Server and Get the Generated HTML. Hope u will got it!!!
-
Sorry for confussion!!! let me explain it to u! Let suppose i have URL = "http://www.some.com" Now in it i have a Grid which depends on some session variables. Now when i use Response.Redirect(URL) the grid reterives the data on the basis of session variables. but when i use HTTPWebRequest to get the HTML which is generated for that URL grid doesn't reterives session values. I have to get the execute the URL on the Server and Get the Generated HTML. Hope u will got it!!!
Sorry but i think you can't do that as Session is store at server side you are accessing the aaplication from the URL Why don't you use query string instead of session varaibles to retrive the data. As per my understanding there is one application that have one url After user enters into website Server side session are get created and store Using this Session values data is coming in Datagrid .
Thanks and Regards Sandeep If If you look at what you do not have in life, you don't have anything, If you look at what you have in life, you have everything... "