1

私のコードは、プロキシを使用していないときに機能しますが、リクエストを送信するときに実際の IP が明らかにならないようにプロキシを使用したいと考えています。プログラムを実行しようとすると、「リモート サーバーがエラーを返しました: (417) Expectation Failed」というエラーが表示されます。「response = CType(request.GetResponse(), HttpWebResponse)」を指しています。私のコードに何か問題がありますか? 私は今本当に混乱しています。どんな助けでも感謝します。

            Dim myProxy As New WebProxy("173.234.249.68", 8800)
            Dim request As HttpWebRequest
            Dim response As HttpWebResponse
            Dim tempCookies As New CookieContainer
            request = CType(WebRequest.Create("http://samplewebsite.com"), HttpWebRequest)
            request.Proxy = myProxy
            request.ContentType = "application/x-www-form-urlencoded"
            request.ContentLength = POST.Length
            request.KeepAlive = True
            request.CookieContainer = tempCookies

            response = CType(request.GetResponse(), HttpWebResponse)
            tempCookies.Add(response.Cookies)
            response.Close()
4

3 に答える 3

1
<Runtime.InteropServices.DllImport("wininet.dll", SetLastError:=True)> _
Private Shared Function InternetSetOption(ByVal hInternet As IntPtr, ByVal dwOption As Integer, ByVal lpBuffer As IntPtr, ByVal lpdwBufferLength As Integer) As Boolean
End Function


Public Structure Struct_INTERNET_PROXY_INFO
    Public dwAccessType As Integer
    Public proxy As IntPtr
    Public proxyBypass As IntPtr
End Structure

Private Sub UseProxy(ByVal strProxy As String)
    Const INTERNET_OPTION_PROXY As Integer = 38
    Const INTERNET_OPEN_TYPE_PROXY As Integer = 3

    Dim struct_IPI As Struct_INTERNET_PROXY_INFO

    struct_IPI.dwAccessType = INTERNET_OPEN_TYPE_PROXY
    struct_IPI.proxy = Marshal.StringToHGlobalAnsi(strProxy)
    struct_IPI.proxyBypass = Marshal.StringToHGlobalAnsi("local")

    Dim intptrStruct As IntPtr = Marshal.AllocCoTaskMem(Marshal.SizeOf(struct_IPI))

    Marshal.StructureToPtr(struct_IPI, intptrStruct, True)

    Dim iReturn As Boolean = InternetSetOption(IntPtr.Zero, INTERNET_OPTION_PROXY, intptrStruct, System.Runtime.InteropServices.Marshal.SizeOf(struct_IPI))
End Sub

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    Label4.Text = (TextBox1.Text & ":" & TextBox2.Text)

End Sub

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
    UseProxy(Label4.Text)
    WebBrowser1.Navigate(TextBox3.Text)
End Sub

クラス終了

于 2016-04-12T22:04:39.720 に答える
0

次の行を変更します。

Dim myProxy As New WebProxy("173.234.249.68", 8800)

Dim myProxy As New WebProxy("173.234.249.68:8800")
于 2016-12-07T19:05:25.593 に答える
0
 Dim myProxy As New WebProxy("173.234.249.68:8800", true)
        Dim request As HttpWebRequest
        Dim response As HttpWebResponse
        Dim tempCookies As New CookieContainer
        request = CType(WebRequest.Create("http://samplewebsite.com"), HttpWebRequest)
        request.Proxy = myProxy
        request.ContentType = "application/x-www-form-urlencoded"
        request.ContentLength = POST.Length
        request.KeepAlive = True
        request.CookieContainer = tempCookies

        response = CType(request.GetResponse(), HttpWebResponse)
        tempCookies.Add(response.Cookies)
        response.Close()
于 2014-12-11T10:03:52.307 に答える