如何使用C#代码设置代理? [英] How to set Proxy with C# code ?

查看:127
本文介绍了如何使用C#代码设置代理?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗨!







如何使用C#设置代理(地址和端口)代码。



非常感谢..

Hi !
.
.

How to set Proxy (Address and Port) with C# code .

Thanks lot ..

推荐答案

看看这篇文章它会对你有所帮助



http://support.microsoft.com/kb/226473
Check out this article it will help you

http://support.microsoft.com/kb/226473


代码片段在VB中,但转换应该很容易...当然,此示例使用8080作为端口...您可以将其更改为任何内容。



Code snippet is in VB but conversion should be easy... Of course, this sample uses 8080 as the port... you can change it to anything.

Dim ioDataStream As Stream
Dim lWebResponse As HttpWebResponse
Dim lWebRequest As HttpWebRequest

Try
    'Create the web request
    lWebRequest = WebRequest.Create("http://mywebpage.com")

    Dim proxyObject As New WebProxy("http://myproxy:8080/", True)
    proxyObject.Credentials = CredentialCache.DefaultNetworkCredentials
    lWebRequest.Proxy = proxyObject
    ' If required by the server, set the credentials.
    lWebRequest.Credentials = CredentialCache.DefaultNetworkCredentials
    'Attach to the response object
    lWebResponse = lWebRequest.GetResponse
    'Funnel the response into the stream reader...
    ioDataStream = lWebResponse.GetResponseStream
Catch ex As Exception
    'Handle exceptions here...

End Try


这篇关于如何使用C#代码设置代理?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆