Using HttpClient to call server API in Unity C#

Описание к видео Using HttpClient to call server API in Unity C#

Unity C# 使用 HttpClient 调用服务器 API
Using HttpClient to call server API in Unity C#

Post_API2(string url,string json,string token)
{
using (var client = new HttpClient())
{
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token);
var request = new HttpRequestMessage(HttpMethod.Post, url);
request.Content = new StringContent(json, Encoding.UTF8, "application/json");

var response = await client.SendAsync(request);

// Process request results
string content = await response.Content.ReadAsStringAsync();
var http_status_code = (int)response.StatusCode;

// Return both response content and status code as a tuple
return new Tuple
}
}

Post_APINoToken(string url,string json)
{
using (var client = new HttpClient())
{
var request = new HttpRequestMessage(HttpMethod.Post, url);
request.Content = new StringContent(json, Encoding.UTF8, "application/json");

var response = await client.SendAsync(request);

// Process request results
string content = await response.Content.ReadAsStringAsync();
var http_status_code = (int)response.StatusCode;

// Return both response content and status code as a tuple
return new Tuple
}
}

Комментарии

Информация по комментариям в разработке