-
Notifications
You must be signed in to change notification settings - Fork 446
/
Copy pathHttpApiRequestMessage.cs
82 lines (73 loc) · 2.84 KB
/
HttpApiRequestMessage.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Net.Http;
using System.Threading.Tasks;
namespace WebApiClientCore
{
/// <summary>
/// 表示 httpApi 的请求消息
/// </summary>
public abstract class HttpApiRequestMessage : HttpRequestMessage
{
/// <summary>
/// 返回使用 uri 值合成的请求URL
/// </summary>
/// <param name="uri">uri值</param>
/// <returns></returns>
public abstract Uri MakeRequestUri(Uri uri);
/// <summary>
/// 追加Query参数到请求路径
/// </summary>
/// <param name="key">参数名</param>
/// <param name="value">参数值</param>
public abstract void AddUrlQuery(string key, string? value);
/// <summary>
/// 添加字段到已有的Content
/// 要求 content-type 为 application/x-www-form-urlencoded
/// </summary>
/// <param name="name">名称</param>
/// <param name="value">值</param>
/// <returns></returns>
public Task AddFormFieldAsync(string name, string? value)
{
var keyValue = new KeyValue(name, value);
return this.AddFormFieldAsync(Enumerable.Repeat(keyValue, 1));
}
/// <summary>
/// 添加字段到已有的Content
/// 要求 content-type 为 application/x-www-form-urlencoded
/// </summary>
/// <param name="keyValues">键值对</param>
/// <exception cref="NotSupportedException"></exception>
/// <returns></returns>
public abstract Task AddFormFieldAsync(IEnumerable<KeyValue> keyValues);
/// <summary>
/// 添加文本内容到已有的Content
/// 要求 content-type 为 multipart/form-data
/// </summary>
/// <param name="name">名称</param>
/// <param name="value">文本</param>
public void AddFormDataText(string name, string? value)
{
var keyValue = new KeyValue(name, value);
this.AddFormDataText([keyValue]);
}
/// <summary>
/// 添加文本内容到已有的Content
/// 要求 content-type 为 multipart/form-data
/// </summary>
/// <param name="keyValues">键值对</param>
public abstract void AddFormDataText(IEnumerable<KeyValue> keyValues);
/// <summary>
/// 添加文件内容到已有的Content
/// 要求 content-type 为 multipart/form-data
/// </summary>
/// <param name="stream">文件流</param>
/// <param name="name">名称</param>
/// <param name="fileName">文件名</param>
/// <param name="contentType">文件Mime</param>
public abstract void AddFormDataFile(Stream stream, string name, string? fileName, string? contentType);
}
}