!用POST方法发送HTTP请求
!!%second%C#版
提供者:成都谊诚,王小蓉
using System.Net;
/// <summary>
/// 这个是用POST方法发送HTTP请求的C#代码,一种通用方法,你要用这个函数把你的数据发出去
/// </summary>
/// <param name="url">即Post Url</param>
/// <param name="postString">即Post数据</param>
/// <returns>即返回</returns>
public static string PostData(string url, string postString) {
byte[] postData = Encoding.UTF8.GetBytes(postString);
WebClient webClient = new WebClient();
webClient.Headers.Add("Content-Type", "application/x-www-form-urlencoded;charset=UTF-8");
byte[] resoponseData = webClient.UploadData(url, "POST", postData);
return Encoding.UTF8.GetString(resoponseData);
}
!!%second%VB版
需引用Microsoft XML,v3.0
Public Function PostData(ByVal sUrl As String, ByVal sData As String) As String
Dim oxh As New MSXML2.XMLHTTP
oxh.Open "post", sUrl, False 'False-同步;True-异步
oxh.setRequestHeader "CONTENT-TYPE", "application/x-www-form-urlencoded;charset=UTF-8"
oxh.send sData
If oxh.readyState = 4 Then
If oxh.Status = 200 Then PostData = oxh.responseText
End If
Set oxh = Nothing
End Function