Skip to content

Commit 2d1f740

Browse files
committed
改为先读出xml文本。 有时候得到的结果不是xml,用stream不方便debug。
1 parent 87e4805 commit 2d1f740

File tree

2 files changed

+27
-2
lines changed

2 files changed

+27
-2
lines changed

src/Api/Base/BaseOssCommand.cs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
using System;
2+
using System.IO;
23
using System.Net;
34
using System.Net.Http;
5+
using System.Text;
46
using System.Threading.Tasks;
57
using Cuiliang.AliyunOssSdk.Api.Common.Consts;
68
using Cuiliang.AliyunOssSdk.Entites;
@@ -116,9 +118,14 @@ private async Task<OssResult<TResult>> ProcessResponseInternal(HttpResponseMessa
116118
//错误的http代码
117119
if (response.Content?.Headers.ContentLength > 0)
118120
{
121+
//var responseContent = await response.Content.ReadAsStreamAsync();
122+
//var errorResult =
123+
// SerializeHelper.Deserialize<ErrorResult>(responseContent);
124+
125+
var responseContent = await response.Content.ReadAsStringAsync();
119126
var errorResult =
120-
SerializeHelper.Deserialize<ErrorResult>(await response.Content.ReadAsStreamAsync());
121-
127+
SerializeHelper.Deserialize<ErrorResult>(responseContent);
128+
122129
return new OssResult<TResult>()
123130
{
124131
IsSuccess = false,

src/Utility/SerializeHelper.cs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,24 @@ public static T Deserialize<T>(Stream xmlStream)
2828

2929
}
3030

31+
/// <summary>
32+
/// XML 文本 -》 对象
33+
/// </summary>
34+
/// <typeparam name="T"></typeparam>
35+
/// <param name="stringContent"></param>
36+
/// <returns></returns>
37+
public static T Deserialize<T>(string stringContent)
38+
{
39+
var serializer = new XmlSerializer(typeof(T));
40+
41+
using (TextReader reader = new StringReader(stringContent))
42+
{
43+
return (T)serializer.Deserialize(reader);
44+
}
45+
46+
47+
}
48+
3149
/// <summary>
3250
/// 将一个对象序列化为XML字符串
3351
/// </summary>

0 commit comments

Comments
 (0)