File tree Expand file tree Collapse file tree 2 files changed +38
-2
lines changed
WebApiClientCore/Attributes/ReturnAttributes Expand file tree Collapse file tree 2 files changed +38
-2
lines changed Original file line number Diff line number Diff line change 1- using System . Net . Http . Headers ;
1+ using System ;
2+ using System . Net . Http . Headers ;
23using System . Threading . Tasks ;
34using WebApiClientCore . HttpContents ;
45
@@ -26,6 +27,23 @@ public JsonReturnAttribute(double acceptQuality)
2627 {
2728 }
2829
30+ /// <summary>
31+ /// 指示响应的ContentType与AcceptContentType是否匹配
32+ /// 返回false则调用下一个ApiReturnAttribute来处理响应结果
33+ /// </summary>
34+ /// <param name="responseContentType">响应的ContentType</param>
35+ /// <returns></returns>
36+ protected override bool IsMatchAcceptContentType ( MediaTypeHeaderValue ? responseContentType )
37+ {
38+ var result = base . IsMatchAcceptContentType ( responseContentType ) ;
39+ if ( result == false )
40+ {
41+ var mediaType = responseContentType ? . MediaType ;
42+ result = string . Equals ( mediaType , "text/json" , StringComparison . OrdinalIgnoreCase ) ;
43+ }
44+ return result ;
45+ }
46+
2947 /// <summary>
3048 /// 设置强类型模型结果值
3149 /// </summary>
Original file line number Diff line number Diff line change 1- using System . Net . Http . Headers ;
1+ using System ;
2+ using System . Net . Http . Headers ;
23using System . Threading . Tasks ;
34using WebApiClientCore . HttpContents ;
45
@@ -26,6 +27,23 @@ public XmlReturnAttribute(double acceptQuality)
2627 {
2728 }
2829
30+ /// <summary>
31+ /// 指示响应的ContentType与AcceptContentType是否匹配
32+ /// 返回false则调用下一个ApiReturnAttribute来处理响应结果
33+ /// </summary>
34+ /// <param name="responseContentType">响应的ContentType</param>
35+ /// <returns></returns>
36+ protected override bool IsMatchAcceptContentType ( MediaTypeHeaderValue ? responseContentType )
37+ {
38+ var result = base . IsMatchAcceptContentType ( responseContentType ) ;
39+ if ( result == false )
40+ {
41+ var mediaType = responseContentType ? . MediaType ;
42+ result = string . Equals ( mediaType , "text/xml" , StringComparison . OrdinalIgnoreCase ) ;
43+ }
44+ return result ;
45+ }
46+
2947 /// <summary>
3048 /// 设置强类型模型结果值
3149 /// </summary>
You can’t perform that action at this time.
0 commit comments