|
|
@@ -152,28 +152,36 @@ namespace Learun.Util |
|
|
|
public static string HttpPosts(string url, string json, WebHeaderCollection header) |
|
|
|
{ |
|
|
|
string result = ""; |
|
|
|
HttpWebRequest req = (HttpWebRequest)WebRequest.Create(url); |
|
|
|
req.Method = "POST"; |
|
|
|
req.ContentType = "application/json;charset=UTF-8"; |
|
|
|
req.Headers.Add(header); |
|
|
|
byte[] data = Encoding.UTF8.GetBytes(json);//把字符串转换为字节 |
|
|
|
try |
|
|
|
{ |
|
|
|
HttpWebRequest req = (HttpWebRequest)WebRequest.Create(url); |
|
|
|
req.Method = "POST"; |
|
|
|
req.ContentType = "application/json;charset=UTF-8"; |
|
|
|
req.Headers.Add(header); |
|
|
|
byte[] data = Encoding.UTF8.GetBytes(json);//把字符串转换为字节 |
|
|
|
|
|
|
|
req.ContentLength = data.Length; //请求长度 |
|
|
|
req.ContentLength = data.Length; //请求长度 |
|
|
|
|
|
|
|
using (Stream reqStream = req.GetRequestStream()) //获取 |
|
|
|
{ |
|
|
|
reqStream.Write(data, 0, data.Length);//向当前流中写入字节 |
|
|
|
reqStream.Close(); //关闭当前流 |
|
|
|
} |
|
|
|
using (Stream reqStream = req.GetRequestStream()) //获取 |
|
|
|
{ |
|
|
|
reqStream.Write(data, 0, data.Length);//向当前流中写入字节 |
|
|
|
reqStream.Close(); //关闭当前流 |
|
|
|
} |
|
|
|
|
|
|
|
HttpWebResponse resp = (HttpWebResponse)req.GetResponse(); //响应结果 |
|
|
|
Stream stream = resp.GetResponseStream(); |
|
|
|
//获取响应内容 |
|
|
|
using (StreamReader reader = new StreamReader(stream, Encoding.UTF8)) |
|
|
|
HttpWebResponse resp = (HttpWebResponse)req.GetResponse(); //响应结果 |
|
|
|
Stream stream = resp.GetResponseStream(); |
|
|
|
//获取响应内容 |
|
|
|
using (StreamReader reader = new StreamReader(stream, Encoding.UTF8)) |
|
|
|
{ |
|
|
|
result = reader.ReadToEnd(); |
|
|
|
} |
|
|
|
return result; |
|
|
|
} |
|
|
|
catch (Exception e) |
|
|
|
{ |
|
|
|
result = reader.ReadToEnd(); |
|
|
|
throw e; |
|
|
|
} |
|
|
|
return result; |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |