询问者
如何Silverlight中通过HttpWebRequest操作Cookie?

问题
-
Silverlight oob方式下无法获得和设置Cookie, 请问怎么办?
HttpWebRequest request = (HttpWebRequest)WebRequest.Create( "http://10.2.69.81:8080/testa" );
request.ContentType = "application/x-www-form-urlencoded; charset=UTF-8";
request.Method = "POST";CookieContainer cookie = new CookieContainer();
string server = "http://10.2.69.81:8080";
cookie.SetCookies(new Uri(server), "JSESSIONID=fIECYGMs1Rd4st6HhllVBlUVc");
request.CookieContainer = cookie;在执行到这里的时候“此类没有实现这一属性”
全部回复
-
现在,通过添加
IWebRequestCreate creator = System.Net.Browser.WebRequestCreator.ClientHttp;
WebRequest.RegisterPrefix("http://", creator);
WebRequest.RegisterPrefix("https://", creator);已经能够操作Cookie。
(详细见https://msdn.microsoft.com/EN-US/library/dd920298%28v=vs.95%29.aspx?f=255&MSPPError=-2147217396
)
现在发现一个新的问题:读取的Cookie并不完整。例如,我有"JSESSIONID=fIECYGMs1Rd4st6HhllVBlUVc-yvEHZ0X6mLVqL3RBwFYWxUAjlC!487762273;ROUTEID=.postwyweb3",在response.Cookies中却只能读到.postwyweb3
这是为什么呢?是BUG吗?
-
你好, 升宝,
首先非常开心你已经解决你最初的问题了。
对于你发现的新问题,我有一点不太明白的地方是,你的整个cookie的值最后是以“postwyweb3”结束的。你说“在response.Cookies中却只能读到.postwyweb3”, 这不就意味着整个cookie的值都已经读取到了吗?为什么你还说没有读取完整?请解释下具体是怎么没读取完整。
另外,如果可以的话,请分享一个完整的示例程序, 关于你是如何读取和设置cookie值的,这样可以帮助我们复现你的问题来确认这是代码问题还是Silverlight本身的问题,谢谢。
MSDN Community Support
Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.