You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
48 lines
1.2 KiB
C#
48 lines
1.2 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
|
|
namespace HttpClientStudy.Core.CustomHttpClient
|
|
{
|
|
/// <summary>
|
|
/// HelloApi
|
|
/// 类型化客户端
|
|
/// </summary>
|
|
public class HelloApiService
|
|
{
|
|
public HttpClient Client { get; set; }
|
|
|
|
public HelloApiService(HttpClient httpClient)
|
|
{
|
|
Client = httpClient;
|
|
}
|
|
|
|
public async Task<string> Ping()
|
|
{
|
|
var content = await Client.GetStringAsync("/api/Hello/Ping");
|
|
return content;
|
|
}
|
|
|
|
public async Task<string> Index()
|
|
{
|
|
var content = await Client.GetStringAsync("/api/Hello/Index");
|
|
return content;
|
|
}
|
|
|
|
public async Task<string> Get()
|
|
{
|
|
var content = await Client.GetStringAsync("/api/Hello/Get");
|
|
return content;
|
|
}
|
|
|
|
public async Task<string> Post()
|
|
{
|
|
var response = await Client.PostAsync("/api/Hello/Post", null);
|
|
var content = await response.Content.ReadAsStringAsync();
|
|
return content;
|
|
}
|
|
}
|
|
}
|