.Net6——Post、Get

public string httpclient(string Url, HttpMethod httpmethod)
{
    try
    {
	//跳过ssl错误
        HttpClientHandler clientHandler = new HttpClientHandler();
        clientHandler.ServerCertificateCustomValidationCallback = (sender, cert, chain, sslPolicyErrors) => { return true; };

        HttpClient client = new HttpClient(clientHandler);
        var request = new HttpRequestMessage
        {
            Method = httpmethod,
            RequestUri = new(Url, UriKind.Absolute)
        };
        request.Headers.Add("Authorization", "bearer " + "afd8ab48-d351-45b3-a6d1-6f7c0b395da3");

        var gettoken_Response = client.Send(request);
        Task<string> cc = gettoken_Response.Content.ReadAsStringAsync();
        return cc.Result;
    }
    catch (Exception ex)
    {

        throw;
    }
    return null;
}
posted @ 2023-01-09 16:17  Panor  阅读(485)  评论(0编辑  收藏  举报