0

你怎么知道 atype是 areference type还是 a value type。例如,根据 about.com 的一篇文章 ( http://visualbasic.about.com/b/2005/10/29/when-is-a-copy-not-a-copy.htm )integer type总是一段value type时间anarray type可以是 avalue type或 a reference type。同样,在复制cookiecontainer必须使用该clone()方法时,还是同样=有效?那将=创建一个副本或一个引用cookiecontainer

注意: 在我看来,通过它在此代码中的使用方式,=创建了一个副本。

来自:http ://howtostartprogramming.com/vb-net/vb-net-tutorial-52-httpwebrequest-cookiecontainer/

Imports System.Net
Imports System.Text
Imports System.IO

Public Class Form1

    Dim logincookie As CookieContainer

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

        Dim postData As String = "referer=http%3A%2F%2Fforums.zybez.net%2Findex.php%3Fapp%3Dcore%26module%3Dglobal%26section%3Dlogin&username=" & TextBox1.Text & "&password=" & TextBox2.Text & "&rememberMe=1"
        Dim tempCookies As New CookieContainer
        Dim encoding As New UTF8Encoding
        Dim byteData As Byte() = encoding.GetBytes(postData)

        Dim postReq As HttpWebRequest = DirectCast(WebRequest.Create("http://forums.zybez.net/index.php?app=core&module=global&section=login&do=process"), HttpWebRequest)
        postReq.Method = "POST"
        postReq.KeepAlive = True
        postReq.CookieContainer = tempCookies
        postReq.ContentType = "application/x-www-form-urlencoded"
        postReq.Referer = "http://forums.zybez.net/index.php?app=core&module=global&section=login&do=process"
        postReq.UserAgent = "Mozilla/5.0 (Windows; U; Windows NT 6.1; ru; rv:1.9.2.3) Gecko/20100401 Firefox/4.0 (.NET CLR 3.5.30729)"
        postReq.ContentLength = byteData.Length

        Dim postreqstream As Stream = postReq.GetRequestStream()
        postreqstream.Write(byteData, 0, byteData.Length)
        postreqstream.Close()
        Dim postresponse As HttpWebResponse

        postresponse = DirectCast(postReq.GetResponse(), HttpWebResponse)
        tempCookies.Add(postresponse.Cookies)
        logincookie = tempCookies
        Dim postreqreader As New StreamReader(postresponse.GetResponseStream())

        Dim thepage As String = postreqreader.ReadToEnd

        RichTextBox1.Text = thepage

    End Sub


    Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click

        Dim request As HttpWebRequest = DirectCast(WebRequest.Create("http://forums.zybez.net/index.php?app=core&module=usercp"), HttpWebRequest)
        request.CookieContainer = logincookie
        Dim response As HttpWebResponse = DirectCast(request.GetResponse(), HttpWebResponse)
        Dim reader As New StreamReader(response.GetResponseStream())
        Dim theusercp As String = reader.ReadToEnd

        RichTextBox2.Text = theusercp

    End Sub
End Class

更新 1

因此,来自 MSDN ( http://msdn.microsoft.com/en-us/library/t63sy5hs.aspx ) 的所有人classes都在reference types制作.cookiecontainerreference type

4

1 回答 1

2

这是你想要的吗:

dim x = 100
dim isValueType = x.GetType.IsValueType
于 2013-08-27T06:50:20.033 回答