如何保持会话和饼干的WebRequest? [英] How to maintain session and cookies to webrequest?

查看:105
本文介绍了如何保持会话和饼干的WebRequest?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建一个具有函数来获取股票的细节的应用程序。它是建立在HTTPS站点发布数据。

我想保持这个呼叫会话状态和饼干。我怎样才能做这个任务?

我在点会话1点2调用函数和功能丧失的会话和饼干。

我如何通过会议,Web请求的URL? Web请求发生在相同的应用服务器。

下面是我的code:

 功能getStockDtl()
    会议(stockid)=123456
    昏暗的URL的String =一些url.aspx
    昏暗的REQ作为的WebRequest = HttpWebRequest.Create(URL)
    昏暗SREAD作为新的StreamReader(req.GetResponse.GetResponseStream)
    昏暗RSTRING的String = sread.ReadToEnd
结束功能


解决方案

首先,这并不似乎是实现你获得股票的详细目标的最佳途径。 Surley如果你正在访问的网站是在同一台服务器上,你可以创建一个Web服务,并调用?

其次,如果你想要得到这个工作,你能不能只是通过查询字符串的URL,而不是试图将其存储在会话(这将是prefered容易的解决方案)

你目前做的是您要添加这个到会话缓存(这是不提供给您做一个Web请求到Web应用程序),你可以解决这个问题通过将值在应用程序将无法正常工作缓存(但我只能这样做,如果这是你设置这届唯一的位置,似乎一般混乱。)

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

解决方案

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.)

这篇关于如何保持会话和饼干的WebRequest?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆