在vb.net中不是web的能写Cookie吗

gxnnyzr 2008-03-20 10:33:01
        Dim myCookie As HttpCookie = New HttpCookie("myCookie")
myCookie("auserid") = "72"
myCookie("username") = "yzr"
myCookie("truename") = "sss"
myCookie("flag") = "1"
...全文
96 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
herol 2008-03-20
  • 打赏
  • 举报
回复

Imports System.Net
Imports System

' This example is run at the command line.
' Specify one argument: the name of the host to
' receive the request.
' If the request is sucessful, the example displays the contents of the cookies
' returned by the host.

Public Class CookieExample

Public Shared Sub Main(args() As String)
If args Is Nothing OrElse args.Length <> 1 Then
Console.WriteLine("Specify the URL to receive the request.")
Environment.Exit(1)
End If
Dim request As HttpWebRequest = CType(WebRequest.Create(args(0)), HttpWebRequest)
request.CookieContainer = New CookieContainer()

Dim response As HttpWebResponse = CType(request.GetResponse(), HttpWebResponse)


' Print the properties of each cookie.
Dim cook As Cookie
For Each 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}", IIf(cook.Version = 1, "2109", "2965"))

' Show the string representation of the cookie.
Console.WriteLine("String: {0}", cook.ToString())
Next cook
End Sub 'Main
End Class 'CookieExample


' Output from this example will be vary depending on the host name specified,
' but will be similar to the following.
'
'Cookie:
'CustomerID = 13xyz
'Domain: .contoso.com
'Path: /
'Port:
'Secure: False
'When issued: 1/14/2003 3:20:57 PM
'Expires: 1/17/2013 11:14:07 AM (expired? False)
'Don't save: False
'Comment:
'Uri for comments:
'Version: RFC 2965
'String: CustomerID = 13xyz
'
herol 2008-03-20
  • 打赏
  • 举报
回复
不是很明白你的意思,看看这个例子能不能对你有帮助吧


Imports System.Net
Imports System

' This example is run at the command line.
' Specify one argument: the name of the host to
' receive the request.
' If the request is sucessful, the example displays the contents of the cookies
' returned by the host.

Public Class CookieExample

Public Shared Sub Main(args() As String)
If args Is Nothing OrElse args.Length <> 1 Then
Console.WriteLine("Specify the URL to receive the request.")
Environment.Exit(1)
End If
Dim request As HttpWebRequest = CType(WebRequest.Create(args(0)), HttpWebRequest)
request.CookieContainer = New CookieContainer()

Dim response As HttpWebResponse = CType(request.GetResponse(), HttpWebResponse)



' Print the properties of each cookie.
Dim cook As Cookie
For Each 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}", IIf(cook.Version = 1, "2109", "2965"))

' Show the string representation of the cookie.
Console.WriteLine("String: {0}", cook.ToString())
Next cook
End Sub 'Main
End Class 'CookieExample



' Output from this example will be vary depending on the host name specified,
' but will be similar to the following.
'
'Cookie:
'CustomerID = 13xyz
'Domain: .contoso.com
'Path: /
'Port:
'Secure: False
'When issued: 1/14/2003 3:20:57 PM
'Expires: 1/17/2013 11:14:07 AM (expired? False)
'Don't save: False
'Comment:
'Uri for comments:
'Version: RFC 2965
'String: CustomerID = 13xyz
'

gxnnyzr 2008-03-20
  • 打赏
  • 举报
回复
可是我又用到WebBrowse
herol 2008-03-20
  • 打赏
  • 举报
回复
WinForm中不能用Cookie,用全局变量存吧
gxnnyzr 2008-03-20
  • 打赏
  • 举报
回复
因为我C/S要用到webBrowse
HimeTale 2008-03-20
  • 打赏
  • 举报
回复
bs是条件有限才用的cookie
cs结构还用cookie....肯定是设计上的问题
直接在本地写个文件,然后登陆的时候去读就行了。
gxnnyzr 2008-03-20
  • 打赏
  • 举报
回复
楼上的,谢谢,这个我看过了.

我是用winfrom的,我有个网站是要Cookie才能登陆,所以要在WINFROM中写入Cookie

16,717

社区成员

发帖
与我相关
我的任务
社区描述
VB技术相关讨论,主要为经典vb,即VB6.0
社区管理员
  • VB.NET
  • 水哥阿乐
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧