Skip to content

Commit

Permalink
UrlEncodedContent使用utf-8编码
Browse files Browse the repository at this point in the history
  • Loading branch information
xljiulang committed Sep 6, 2018
1 parent 3f3eed4 commit 3004fb7
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions WebApiClient/Internal/HttpContents/UrlEncodedContent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,9 @@ public async Task AddFormFieldAsync(IEnumerable<KeyValuePair<string, string>> ke
{
builder.Append('&');
}
builder.Append(HttpUtility.UrlEncode(pair.Key, Encoding.ASCII));
builder.Append(Encode(pair.Key));
builder.Append('=');
builder.Append(HttpUtility.UrlEncode(pair.Value, Encoding.ASCII));
builder.Append(Encode(pair.Value));
}

if (this.stream.Length > 0)
Expand All @@ -75,6 +75,16 @@ public async Task AddFormFieldAsync(IEnumerable<KeyValuePair<string, string>> ke
await this.stream.WriteAsync(bytes, 0, bytes.Length).ConfigureAwait(false);
}

/// <summary>
/// 表单编码
/// </summary>
/// <param name="value">值</param>
/// <returns></returns>
private static string Encode(string value)
{
return HttpUtility.UrlEncode(value, Encoding.UTF8);
}

/// <summary>
/// 计算内容长度
/// </summary>
Expand Down

0 comments on commit 3004fb7

Please sign in to comment.