WeChat public platform development: Web proxy function

高洛峰
Release: 2017-02-27 13:47:23
Original
2307 people have browsed it

Starting from Senparc.Weixin.dll v4.5.7, we provide a Web proxy function to facilitate applications in restricted LANs to call interfaces smoothly.

The relevant modifications are in Senparc.Weixin/Utilities/HttpUtility/RequestUtility.cs:

#region 代理

        private static WebProxy _webproxy = null;

        /// <summary>
        /// 设置Web代理
        /// </summary>
        /// <param name="host"></param>
        /// <param name="port"></param>
        /// <param name="username"></param>
        /// <param name="password"></param>
        public static void SetHttpProxy(string host, string port, string username, string password)
        {
            ICredentials cred;
            cred = new NetworkCredential(username, password);
            if (!string.IsNullOrEmpty(host))
            {
                _webproxy = new WebProxy(host + ":" + port ?? "80", true, null, cred);
            }
        }

        /// <summary>
        /// 清除Web代理状态
        /// </summary>
        public static void RemoveHttpProxy()
        {
            _webproxy = null;
        }

        #endregion
Copy after login

The usage method is as follows:

1. Set the proxy message before calling the interface (Only needed once globally):

//设置
RequestUtility.SetHttpProxy("http://192.168.1.130","8088","username","pwd");
Copy after login

2. When the interface method is called normally, this proxy parameter will be automatically applied.

When the proxy status needs to be cleared, the RemoveHttpProxy() method is executed globally:

//清除
RequestUtility.RemoveHttpProxy();
Copy after login


For more articles related to WeChat public platform development: Web proxy function, please pay attention PHP Chinese website!


Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!