|
3 | 3 | using System.Collections.Specialized; |
4 | 4 | using System.Text; |
5 | 5 | using System.IO; |
| 6 | +using System.Linq; |
6 | 7 | using System.Net; |
7 | 8 | using Qiniu.Util; |
8 | 9 |
|
@@ -633,7 +634,8 @@ public HttpResult PostJson(string url, string data, string token, bool binaryMod |
633 | 634 | wReq.AllowWriteStreamBuffering = true; |
634 | 635 | using (Stream sReq = wReq.GetRequestStream()) |
635 | 636 | { |
636 | | - sReq.Write(Encoding.UTF8.GetBytes(data), 0, data.Length); |
| 637 | + byte[] utf8Data = Encoding.UTF8.GetBytes(data); |
| 638 | + sReq.Write(utf8Data, 0, utf8Data.Length); |
637 | 639 | sReq.Flush(); |
638 | 640 | } |
639 | 641 | } |
@@ -750,7 +752,8 @@ public HttpResult PostText(string url, string data, string token, bool binaryMod |
750 | 752 | wReq.AllowWriteStreamBuffering = true; |
751 | 753 | using (Stream sReq = wReq.GetRequestStream()) |
752 | 754 | { |
753 | | - sReq.Write(Encoding.UTF8.GetBytes(data), 0, data.Length); |
| 755 | + byte[] utf8Data = Encoding.UTF8.GetBytes(data); |
| 756 | + sReq.Write(utf8Data, 0, utf8Data.Length); |
754 | 757 | sReq.Flush(); |
755 | 758 | } |
756 | 759 | } |
@@ -864,16 +867,14 @@ public HttpResult PostForm(string url, Dictionary<string, string> kvData, string |
864 | 867 |
|
865 | 868 | if (kvData != null) |
866 | 869 | { |
867 | | - StringBuilder sbb = new StringBuilder(); |
868 | | - foreach (var kv in kvData) |
869 | | - { |
870 | | - sbb.AppendFormat("{0}={1}&", Uri.EscapeDataString(kv.Key), Uri.EscapeDataString(kv.Value)); |
871 | | - } |
| 870 | + string data = string.Join("&", |
| 871 | + kvData.Select(kvp => Uri.EscapeDataString(kvp.Key) + "=" + Uri.EscapeDataString(kvp.Value))); |
872 | 872 |
|
873 | 873 | wReq.AllowWriteStreamBuffering = true; |
874 | 874 | using (Stream sReq = wReq.GetRequestStream()) |
875 | 875 | { |
876 | | - sReq.Write(Encoding.UTF8.GetBytes(sbb.ToString()), 0, sbb.Length - 1); |
| 876 | + byte[] utf8Data = Encoding.UTF8.GetBytes(data); |
| 877 | + sReq.Write(utf8Data, 0, utf8Data.Length); |
877 | 878 | sReq.Flush(); |
878 | 879 | } |
879 | 880 | } |
@@ -990,7 +991,8 @@ public HttpResult PostForm(string url, string data, string token, bool binaryMod |
990 | 991 | wReq.AllowWriteStreamBuffering = true; |
991 | 992 | using (Stream sReq = wReq.GetRequestStream()) |
992 | 993 | { |
993 | | - sReq.Write(Encoding.UTF8.GetBytes(data), 0, data.Length); |
| 994 | + byte[] utf8Data = Encoding.UTF8.GetBytes(data); |
| 995 | + sReq.Write(utf8Data, 0, utf8Data.Length); |
994 | 996 | sReq.Flush(); |
995 | 997 | } |
996 | 998 | } |
|
0 commit comments