如何在webkit cairo.net中设置代理?

如何在webkit cairo.net中设置代理?

问题描述:

大家好,
我的应用程序中有webkit cairo Web浏览器,可用于连接到互联网
使用代理,为此,我使用了这两个代码,这些代码没有给我任何结果:

Hi everybody,
I have webkit cairo web browser in my application which i use to connect to internet
using proxy and for that i use these two codes which didn''t give me any result :

Imports System.Collections.Generic
Imports System.IO
Imports System.Net
Module ProxyMd

    Class simplehttp
        Public Function geturl(url As String, proxyip As String, port As Integer, proxylogin As String, proxypassword As String) As String
            Dim resp As HttpWebResponse
            Dim req As HttpWebRequest = DirectCast(WebRequest.Create(url), HttpWebRequest)
            req.UserAgent = "Mozilla/5.0″"
            req.AllowAutoRedirect = True
            req.ReadWriteTimeout = 5000
            req.CookieContainer = New CookieContainer()
            req.Referer = ""
            req.Headers.[Set]("Accept-Language", "en,en-us")
            Dim stream_in As StreamReader

            Dim proxy As New WebProxy(proxyip, port)
            'if proxylogin is an empty string then don’t use proxy credentials (open proxy)
            If proxylogin = "" Then
                proxy.Credentials = New NetworkCredential(proxylogin, proxypassword)
            End If
            req.Proxy = proxy

            Dim response As String = ""
            Try
                resp = DirectCast(req.GetResponse(), HttpWebResponse)
                stream_in = New StreamReader(resp.GetResponseStream())
                response = stream_in.ReadToEnd()
                stream_in.Close()
            Catch ex As Exception
            End Try
            Return response
        End Function

        Public Function getposturl(url As String, postdata As String, proxyip As String, port As Short, proxylogin As String, proxypassword As String) As String
            Dim resp As HttpWebResponse
            Dim req As HttpWebRequest = DirectCast(WebRequest.Create(url), HttpWebRequest)
            req.UserAgent = "Mozilla/5.0″"
            req.AllowAutoRedirect = True
            req.ReadWriteTimeout = 5000
            req.CookieContainer = New CookieContainer()
            req.Method = "POST"
            req.ContentType = "application/x-www-form-urlencoded"
            req.ContentLength = postdata.Length
            req.Referer = ""

            Dim proxy As New WebProxy(proxyip, port)
            'if proxylogin is an empty string then don’t use proxy credentials (open proxy)
            If proxylogin = "" Then
                proxy.Credentials = New NetworkCredential(proxylogin, proxypassword)
            End If
            req.Proxy = proxy

            Dim stream_out As New StreamWriter(req.GetRequestStream(), System.Text.Encoding.ASCII)
            stream_out.Write(postdata)
            stream_out.Close()
            Dim response As String = ""

            Try
                resp = DirectCast(req.GetResponse(), HttpWebResponse)
                Dim resStream As Stream = resp.GetResponseStream()
                Dim stream_in As New StreamReader(req.GetResponse().GetResponseStream())
                response = stream_in.ReadToEnd()
                stream_in.Close()
            Catch ex As Exception
            End Try
            Return response
        End Function
    End Class
End Module


另一个代码:


another code:

#region "Using Proxy"
  <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
#end region 


现在,我需要高效地使用Webkit Web浏览器,并且我想知道如何在浏览器中设置代理设置.
任何帮助将不胜感激.


Now i need to use webkit web browser execlusivly and i want to know how to set proxy settings in my browser.
Any help will be appreciated.

尝试:
http://www.dotnetspider.com/resources/42674- Setting-IE-proxy-from-vb-net-applications.aspx [
Try:
http://www.dotnetspider.com/resources/42674-Setting-IE-proxy-from-vb-net-applications.aspx[^]


您好Kuthuparakkal先生,
感谢您的快速答复,我真的很感激.但不幸的是,您提供给我的代码无法正常工作.我认为原因是Webkit Web浏览器不接受IE代理.
我需要知道如何在我的webkit cairo浏览器中设置代理吗?
再次感谢Kuthuparakkal.
Hi Mr Kuthuparakkal,
Thank you for your quick reply and i''m really appreciating. but for my bad luck the code that you gave me did not work. the reason i think is that webkit web browser do not accept IE proxy.
I need to know how to set proxy in my webkit cairo browser?
Thank you once again Kuthuparakkal.