C# Class Senparc.Weixin.HttpUtility.RequestUtility

Show file Open project: JeffreySu/WeiXinMPSDK Class Usage Examples

Public Methods

Method Description
AsUrlData ( this data ) : string

将 URL 中的参数名称/值编码为合法的格式。

可以解决类似这样的问题:假设参数名为 tvshow, 参数值为 Tom&Jerry,如果不编码,可能得到的网址: http://a.com/?tvshow=Tom&Jerry&year=1965 编码后则为:http://a.com/?tvshow=Tom%26Jerry&year=1965

实践中经常导致问题的字符有:'&', '?', '=' 等

FillFormDataStream ( string>.this formData, Stream stream ) : void

填充表单信息的Stream

FillFormDataStreamAsync ( string>.this formData, Stream stream ) : System.Threading.Tasks.Task

填充表单信息的Stream

GetQueryString ( string>.this formData ) : string

组装QueryString的方法 参数之间用&连接,首位没有符号,如:a=1&b=2&c=3

HtmlDecode ( this html ) : string

封装System.Web.HttpUtility.HtmlDecode

HtmlEncode ( this html ) : string

封装System.Web.HttpUtility.HtmlEncode

HttpGet ( string url, CookieContainer cookieContainer = null, Encoding encoding = null, X509Certificate cer = null, int timeOut = Config.TIME_OUT ) : string

使用Get方法获取字符串结果(加入Cookie)

HttpGet ( string url, Encoding encoding = null ) : string

使用Get方法获取字符串结果(没有加入Cookie)

HttpGetAsync ( string url, CookieContainer cookieContainer = null, Encoding encoding = null, X509Certificate cer = null, int timeOut = Config.TIME_OUT ) : Task

使用Get方法获取字符串结果(加入Cookie)

HttpGetAsync ( string url, Encoding encoding = null ) : Task

使用Get方法获取字符串结果(没有加入Cookie)

HttpPost ( string url, CookieContainer cookieContainer = null, string>.Dictionary formData = null, Encoding encoding = null, X509Certificate cer = null, int timeOut = Config.TIME_OUT ) : string

使用Post方法获取字符串结果,常规提交

HttpPost ( string url, CookieContainer cookieContainer = null, Stream postStream = null, string>.Dictionary fileDictionary = null, string refererUrl = null, Encoding encoding = null, X509Certificate cer = null, int timeOut = Config.TIME_OUT, bool checkValidationResult = false ) : string

使用Post方法获取字符串结果

HttpPostAsync ( string url, CookieContainer cookieContainer = null, string>.Dictionary formData = null, Encoding encoding = null, X509Certificate cer = null, int timeOut = Config.TIME_OUT ) : Task

使用Post方法获取字符串结果,常规提交

HttpPostAsync ( string url, CookieContainer cookieContainer = null, Stream postStream = null, string>.Dictionary fileDictionary = null, string refererUrl = null, Encoding encoding = null, X509Certificate cer = null, int timeOut = Config.TIME_OUT, bool checkValidationResult = false ) : Task

使用Post方法获取字符串结果

RemoveHttpProxy ( ) : void

清除Web代理状态

SetHttpProxy ( string host, string port, string username, string password ) : void

设置Web代理

UrlDecode ( this url ) : string

封装System.Web.HttpUtility.UrlDecode

UrlEncode ( this url ) : string

封装System.Web.HttpUtility.UrlEncode

Private Methods

Method Description
CheckValidationResult ( object sender, X509Certificate certificate, X509Chain chain, SslPolicyErrors errors ) : bool

验证服务器证书

IsWeixinClientRequest ( this httpContext ) : bool

Method Details

AsUrlData() public static method

将 URL 中的参数名称/值编码为合法的格式。

可以解决类似这样的问题:假设参数名为 tvshow, 参数值为 Tom&Jerry,如果不编码,可能得到的网址: http://a.com/?tvshow=Tom&Jerry&year=1965 编码后则为:http://a.com/?tvshow=Tom%26Jerry&year=1965

实践中经常导致问题的字符有:'&', '?', '=' 等

public static AsUrlData ( this data ) : string
data this
return string

FillFormDataStream() public static method

填充表单信息的Stream
public static FillFormDataStream ( string>.this formData, Stream stream ) : void
formData string>.this
stream Stream
return void

FillFormDataStreamAsync() public static method

填充表单信息的Stream
public static FillFormDataStreamAsync ( string>.this formData, Stream stream ) : System.Threading.Tasks.Task
formData string>.this
stream Stream
return System.Threading.Tasks.Task

GetQueryString() public static method

组装QueryString的方法 参数之间用&连接,首位没有符号,如:a=1&b=2&c=3
public static GetQueryString ( string>.this formData ) : string
formData string>.this
return string

HtmlDecode() public static method

封装System.Web.HttpUtility.HtmlDecode
public static HtmlDecode ( this html ) : string
html this
return string

HtmlEncode() public static method

封装System.Web.HttpUtility.HtmlEncode
public static HtmlEncode ( this html ) : string
html this
return string

HttpGet() public static method

使用Get方法获取字符串结果(加入Cookie)
public static HttpGet ( string url, CookieContainer cookieContainer = null, Encoding encoding = null, X509Certificate cer = null, int timeOut = Config.TIME_OUT ) : string
url string
cookieContainer System.Net.CookieContainer
encoding System.Text.Encoding
cer System.Security.Cryptography.X509Certificates.X509Certificate 证书,如果不需要则保留null
timeOut int
return string

HttpGet() public static method

使用Get方法获取字符串结果(没有加入Cookie)
public static HttpGet ( string url, Encoding encoding = null ) : string
url string
encoding System.Text.Encoding
return string

HttpGetAsync() public static method

使用Get方法获取字符串结果(加入Cookie)
public static HttpGetAsync ( string url, CookieContainer cookieContainer = null, Encoding encoding = null, X509Certificate cer = null, int timeOut = Config.TIME_OUT ) : Task
url string
cookieContainer System.Net.CookieContainer
encoding System.Text.Encoding
cer System.Security.Cryptography.X509Certificates.X509Certificate 证书,如果不需要则保留null
timeOut int
return Task

HttpGetAsync() public static method

使用Get方法获取字符串结果(没有加入Cookie)
public static HttpGetAsync ( string url, Encoding encoding = null ) : Task
url string
encoding System.Text.Encoding
return Task

HttpPost() public static method

使用Post方法获取字符串结果,常规提交
public static HttpPost ( string url, CookieContainer cookieContainer = null, string>.Dictionary formData = null, Encoding encoding = null, X509Certificate cer = null, int timeOut = Config.TIME_OUT ) : string
url string
cookieContainer System.Net.CookieContainer
formData string>.Dictionary
encoding System.Text.Encoding
cer System.Security.Cryptography.X509Certificates.X509Certificate
timeOut int
return string

HttpPost() public static method

使用Post方法获取字符串结果
public static HttpPost ( string url, CookieContainer cookieContainer = null, Stream postStream = null, string>.Dictionary fileDictionary = null, string refererUrl = null, Encoding encoding = null, X509Certificate cer = null, int timeOut = Config.TIME_OUT, bool checkValidationResult = false ) : string
url string
cookieContainer System.Net.CookieContainer
postStream Stream
fileDictionary string>.Dictionary 需要上传的文件,Key:对应要上传的Name,Value:本地文件名
refererUrl string
encoding System.Text.Encoding
cer System.Security.Cryptography.X509Certificates.X509Certificate 证书,如果不需要则保留null
timeOut int
checkValidationResult bool 验证服务器证书回调自动验证
return string

HttpPostAsync() public static method

使用Post方法获取字符串结果,常规提交
public static HttpPostAsync ( string url, CookieContainer cookieContainer = null, string>.Dictionary formData = null, Encoding encoding = null, X509Certificate cer = null, int timeOut = Config.TIME_OUT ) : Task
url string
cookieContainer System.Net.CookieContainer
formData string>.Dictionary
encoding System.Text.Encoding
cer System.Security.Cryptography.X509Certificates.X509Certificate
timeOut int
return Task

HttpPostAsync() public static method

使用Post方法获取字符串结果
public static HttpPostAsync ( string url, CookieContainer cookieContainer = null, Stream postStream = null, string>.Dictionary fileDictionary = null, string refererUrl = null, Encoding encoding = null, X509Certificate cer = null, int timeOut = Config.TIME_OUT, bool checkValidationResult = false ) : Task
url string
cookieContainer System.Net.CookieContainer
postStream Stream
fileDictionary string>.Dictionary 需要上传的文件,Key:对应要上传的Name,Value:本地文件名
refererUrl string
encoding System.Text.Encoding
cer System.Security.Cryptography.X509Certificates.X509Certificate
timeOut int
checkValidationResult bool 验证服务器证书回调自动验证
return Task

RemoveHttpProxy() public static method

清除Web代理状态
public static RemoveHttpProxy ( ) : void
return void

SetHttpProxy() public static method

设置Web代理
public static SetHttpProxy ( string host, string port, string username, string password ) : void
host string
port string
username string
password string
return void

UrlDecode() public static method

封装System.Web.HttpUtility.UrlDecode
public static UrlDecode ( this url ) : string
url this
return string

UrlEncode() public static method

封装System.Web.HttpUtility.UrlEncode
public static UrlEncode ( this url ) : string
url this
return string