本文介绍了HttpWebRequest& HttpWebResponse Cookies的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 29岁程序员,3月因学历无情被辞! 我有一个Windows窗体应用程序,它生成请求,下载图像,并等待用户 输入登录信息。不幸的是,这个图像是动态的,并且基于会话数据。我在HttpWebRequest的CookieCollection属性上读取了的文档。目前,我的代码中有 功能,可以接受cookie,并在新的HttpWebRequest时返回它们; 但是,在进一步检查返回的HttpWebResponse时。 Cookies属性,我注意到 不会返回关于我的会话数据应该存在的cookie(一个这样的名为, cookie命名为JSESSIONID)。还有哪些其他方法可以检索 包含会话数据的cookie? 这是一段代码片段(请原谅wordwrap) Dim strURL As String =" https://www.thisurlisatest.com/" Dim objHTTPRequest As HttpWebRequest = CType(WebRequest.Create(strURL) ,HttpWebRequest) objHTTPRequest.CookieContainer = New CookieContainer() Dim objHTTPResponse As HttpWebResponse = CType(objHTTPRequest.GetResponse(),HttpWebResponse) Dim objReceiveStream As Stream = objHTTPResponse.GetResponseStream() ''我在这里成功检索到了cookies m_Cookies = objHTTPResponse.Cookies Dim objCookie As Cookie 每个objCookie在m_Cookies中 Console.WriteLine(objCookie.Name +" =" + objCookie.Value) 下一个 ''这只输出:language_pref = en_US ''应该有更多包含会话ID数据的cookie 提前感谢你可以解决这个问题, Jeff CheungI have a windows form application that generates a request, downloads an image, and waits the userto enter in login info. Unfortunately, this image is dynamic and based on session data. I haveread documents on the CookieCollection property of HttpWebRequest. Currently, I have thefunctionality in my code to be able to accept cookies, and return them upon a new HttpWebRequest;however, upon further inspection of the returning HttpWebResponse.Cookies property, I notice thatthe cookies that are supposed to be there regarding my session data are not returned (one suchcookie named, JSESSIONID). What other methods are there available to me to retrieve cookies thatwould contain session data?Here is a code snippet (please excuse the wordwrap)Dim strURL As String = "https://www.thisurlisatest.com/"Dim objHTTPRequest As HttpWebRequest = CType(WebRequest.Create(strURL), HttpWebRequest)objHTTPRequest.CookieContainer = New CookieContainer()Dim objHTTPResponse As HttpWebResponse = CType(objHTTPRequest.GetResponse(), HttpWebResponse)Dim objReceiveStream As Stream = objHTTPResponse.GetResponseStream()'' I successfully retrieve the cookies herem_Cookies = objHTTPResponse.CookiesDim objCookie As CookieFor Each objCookie In m_CookiesConsole.WriteLine(objCookie.Name + "=" + objCookie.Value)Next'' This only outputs this: language_pref=en_US'' There should be more cookies that contain session id dataThanks in advance for any light you can shed on this matter,Jeff Cheung推荐答案 这篇关于HttpWebRequest& HttpWebResponse Cookies的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云!
07-22 11:39
查看更多