1

I have created an application that has a function to get stock detail. It is created to post data on an HTTPS site.

I want to maintain the session state and cookies in this call. How can I do this task?

I have the session in point 1. Point 2 invokes the function and the function loses the session and cookies.

How do I pass session to the web request URL? The web request happens in the same application server.

Here is my code:

Function getStockDtl()
    session("stockid")="123456"
    Dim url As String = "some url.aspx"
    Dim req As WebRequest = HttpWebRequest.Create(url)
    Dim sread As New StreamReader(req.GetResponse.GetResponseStream)
    Dim RString As String = sread.ReadToEnd
End Function
Zeeju
  • 99
  • 1
  • 11

2 Answers2

2

Firstly this doesnt seems like the best way to achieve your aim of getting Stock details. Surley if the web site you are accessing is on the same server you could create a web service and call that ?

Secondly if you want to get this to work can you not just pass a querystring to the url rather than trying to store it in session (this would be prefered easy-solution)

What you are currently doing will not work as you are adding this to the session cache (which is not available to the web application you are making a web request to), you could get around this by putting the value in the application cache (but I would only do this if this is the only location you set this session, and it seems generally messy.)

Waqar
  • 758
  • 4
  • 15
-1

See this post for information on how to add a CookieContainer and make multiple requests using the same session information:

Multiple WebRequest in same session

Community
  • 1
  • 1
tpartee
  • 548
  • 7
  • 20
  • Whilst this may theoretically answer the question, [it would be preferable](//meta.stackoverflow.com/q/8259) to include the essential parts of the answer here, and provide the link for reference. – Tunaki Feb 13 '16 at 11:53
  • @tunaki Ideally this answer should be closed as a duplicate of the question I linked but I don't have the editing power to do that. – tpartee Feb 16 '16 at 00:25