40 lines
1.3 KiB
C#
40 lines
1.3 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Net;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
|
|
namespace Hg.Core.Domain
|
|
{
|
|
public static class StockHttpHelper
|
|
{
|
|
public static string PostAjaxData(string url, string param, string Authorization, bool jsonContentType)
|
|
{
|
|
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
|
|
request.Method = "POST";
|
|
if (jsonContentType)
|
|
{
|
|
request.ContentType = "application/json;charet=utf-8";
|
|
}
|
|
//request.Headers.Add("dataType", "json");
|
|
//request.Headers.Add("type", "post");
|
|
if (!string.IsNullOrEmpty(Authorization))
|
|
{
|
|
request.Headers.Add("Authorization", Authorization);
|
|
}
|
|
byte[] data = Encoding.UTF8.GetBytes(param);
|
|
|
|
using (BinaryWriter reqStream = new BinaryWriter(request.GetRequestStream()))
|
|
{
|
|
reqStream.Write(data, 0, data.Length);
|
|
}
|
|
using (HttpWebResponse response = (HttpWebResponse)request.GetResponse())
|
|
{
|
|
StreamReader reader = new StreamReader(response.GetResponseStream(), Encoding.UTF8);
|
|
string result = reader.ReadToEnd();
|
|
return result;
|
|
}
|
|
}
|
|
}
|
|
} |