c#控制台请求第三方api
Dictionary<string, string> Dictioary = new Dictionary<string, string>
{
token :
项目id:
Program program = new Program();
program.GetAsync("第三方api", Dictioary, false);
};
public async Task<string> GetAsync(string url, Dictionary<string, string> header = null, bool Gzip = false)
{
HttpClient client = new HttpClient(new HttpClientHandler() { UseCookies = false });
if (header != null)
{
client.DefaultRequestHeaders.Clear();
foreach (var item in header)
{
client.DefaultRequestHeaders.Add(item.Key, item.Value);
}
}
HttpResponseMessage response = await client.GetAsync(url);
response.EnsureSuccessStatusCode();//用来抛异常的
string responseBody