[성현모] CPMeta , Netstandard 오류 수정
This commit is contained in:
@ -4,21 +4,24 @@ using System.Collections.Generic;
|
||||
using System.Net;
|
||||
using System.Net.Http;
|
||||
using System.Text;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace CPMeta
|
||||
{
|
||||
public class RestAPI
|
||||
{
|
||||
{
|
||||
private static HttpClient RequestClient = new HttpClient();
|
||||
private static HttpClient ResponseClient = new HttpClient();
|
||||
|
||||
public static int TimeOut { get; set; } = 3000;
|
||||
|
||||
static RestAPI()
|
||||
{
|
||||
ServicePointManager.ServerCertificateValidationCallback += (sender, cert, chain, sslPolicyErrors) => true;
|
||||
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;
|
||||
RequestClient.Timeout = TimeSpan.FromMilliseconds(10000);
|
||||
ResponseClient.Timeout = TimeSpan.FromMilliseconds(10000);
|
||||
|
||||
RequestClient.Timeout = TimeSpan.FromMilliseconds(TimeOut);
|
||||
}
|
||||
|
||||
public static async Task<RESPONSE> PostAsync<REQUEST,RESPONSE>(string Url, REQUEST body) where REQUEST : class where RESPONSE : class
|
||||
@ -27,9 +30,12 @@ namespace CPMeta
|
||||
{
|
||||
if (body != null)
|
||||
{
|
||||
var jsonBody = JsonConvert.SerializeObject(body);
|
||||
var contents = new StringContent(jsonBody, Encoding.UTF8, "application/json");
|
||||
Console.WriteLine($"PostAsync:{Url},{JsonConvert.SerializeObject(body, Formatting.Indented)}");
|
||||
|
||||
var jsonBody = JsonConvert.SerializeObject(body);
|
||||
var contents = new StringContent(jsonBody, Encoding.UTF8, "application/json");
|
||||
|
||||
//RequestClient.Timeout = TimeSpan.FromMilliseconds(TimeOut);
|
||||
var response = await RequestClient.PostAsync(Url, contents);
|
||||
|
||||
var resContentStr = await response.Content.ReadAsStringAsync();
|
||||
@ -38,6 +44,7 @@ namespace CPMeta
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Console.WriteLine($"TimeOut: {ResponseClient.Timeout}");
|
||||
Console.WriteLine("PostAsync Error");
|
||||
Console.WriteLine(e.Message);
|
||||
}
|
||||
@ -49,6 +56,9 @@ namespace CPMeta
|
||||
{
|
||||
try
|
||||
{
|
||||
Console.WriteLine($"GetAsync:{Url}");
|
||||
|
||||
//ResponseClient.Timeout = TimeSpan.FromMilliseconds(TimeOut);
|
||||
var response = await ResponseClient.GetAsync(Url);
|
||||
|
||||
var resContentStr = await response.Content.ReadAsStringAsync();
|
||||
@ -57,6 +67,7 @@ namespace CPMeta
|
||||
}
|
||||
catch(Exception e)
|
||||
{
|
||||
Console.WriteLine($"TimeOut: {ResponseClient.Timeout}");
|
||||
Console.WriteLine("GetAsync Error");
|
||||
Console.WriteLine(e.Message);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user