using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Net;
using System.Text;
using System.Threading.Tasks;
namespace _SCscHero.Base.Help
{
public class HttpHelp
{
public static string Get(string url, Dictionary<string, string> param = null, Dictionary<string, string> headers = null)
{
if (param != null)
{
url = url + "?";
url = param.Aggregate(url, (current, item) => current + item.Key + "=" + item.Value + "&");
url = url.Substring(0, url.Length - 1);
}
HttpWebRequest request = WebRequest.Create(url) as HttpWebRequest;
request.Method = "GET";
if (headers != null)
{
foreach (var item in headers)
{
request.Headers[item.Key] = item.Value;
}
}
HttpWebResponse res;
try
{
res = (HttpWebResponse)request.GetResponse();
}
catch (WebException ex)
{
res = (HttpWebResponse)ex.Response;
}
StreamReader sr = new StreamReader(res.GetResponseStream(), Encoding.UTF8);
string content = sr.ReadToEnd();
return content;
}
public static string Post(string url, Dictionary<String, String> param, Dictionary<string, string> headers = null)
{
#region 写日记
string parameterSt