/// <summary>
/// 调用获取接口返回信息
/// </summary>
/// <param name="url">接口地址</param>
/// <param name="data">参数对象</param>
/// <returns></returns>
public string HttpPost(string url, string data)
{
string returnData = "";
try
{
//byte[] buffer = Encoding.GetEncoding("GBK").GetBytes(data);
byte[] buffer = Encoding.UTF8.GetBytes(data);
HttpWebRequest webReq = (HttpWebRequest)WebRequest.Create(url);
webReq.Method = "POST";
webReq.ContentType = "application/json";
webReq.ContentLength = buffer.Length;
Stream postData = webReq.GetRequestStream();
postData.Write(buffer, 0, buffer.Length);
C#调用Post请求
最新推荐文章于 2025-02-22 10:32:47 发布