aliyun / aliyun-oss-csharp-sdk

Aliyun OSS SDK for C#
MIT License
381 stars 206 forks source link

.net core版本SendCore()方法抛出 “无法发送具有此谓词类型的内容正文”意外! #87

Closed xiaoyuvax closed 3 years ago

xiaoyuvax commented 5 years ago

.net core版本SendCore()方法抛出 “无法发送具有此谓词类型的内容正文”意外!但.net版本没有这个问题。

core版本抛出意外的地方:

protected override ServiceResponse SendCore(ServiceRequest request, ExecutionContext context) { var req = new HttpRequestMessage(Convert(request.Method), request.BuildRequestUri()); this.SetRequestContent(req, request); this.SetHeaders(req, request); HttpClient client = GetClient(); HttpResponseMessage resp = client.SendAsync(req, HttpCompletionOption.ResponseHeadersRead).Result; return new ResponseImpl(resp); }

.net版本是这样实现的:

protected override ServiceResponse SendCore(ServiceRequest serviceRequest, ExecutionContext context) { var request = HttpFactory.CreateWebRequest(serviceRequest, Configuration); SetRequestContent(request, serviceRequest, Configuration); try { var response = request.GetResponse() as HttpWebResponse; return new ResponseImpl(response); } catch (WebException ex) { return HandleException(ex); } }

高度怀疑.net core的实现方法有BUG。 这个问题已经导致我们无法使用.net core版本的解决方案。希望有人能解决下。

huiguangjun commented 5 years ago

你们调用的代码是怎么样的,然后在哪个环境下运行?

另外,可以通过 ClientConfiguration.UseNewServiceClient = false 切换到 老的实现方式。

xiaoyuvax commented 5 years ago

采用 ClientConfiguration.UseNewServiceClient = false 之后,工作正常了。 原来就是调用GetObject() var client = new OssClient(_host, _id, _key); client.GetObject(bucket == null ? DEFAULT_BUCKET : bucket, remotePath) ……

remotePath内含路径,不知道是不是路径造成的。

huiguangjun commented 5 years ago

能不能贴一下 remotePath 的 具体内容, 本地我也测试一下。 需要保护的部分,你可以用* 表示。

xiaoyuvax commented 5 years ago

就是一个avatar/1.png 这样的相对路径。

fanruinet commented 5 years ago

OssBug.zip 我遇到了同样的问题。如果运行时是.NET Framework,那么100%出现这个异常。如果运行时是.NET Core,那么不会出现这个异常。 复现bug的项目见附件。 原因是在不接受HTTP Request Body的请求中(例如HEAD)设置了不为空的Request Body: \sdk\Common\Communication\netcore\ServiceClientNewImpl.cs Line 173: requestMsg.Content = new System.Net.Http.ByteArrayContent(new byte[0]);

hjqcan commented 4 years ago

把aliyun oss封装进一个.net standard类库里,然后让.net framework 项目调用这个standard项目,GetObject的时候100%出现这个异常,麻烦修复。

magicjefflee commented 3 years ago

OssBug.zip 我遇到了同样的问题。如果运行时是.NET Framework,那么100%出现这个异常。如果运行时是.NET Core,那么不会出现这个异常。 复现bug的项目见附件。 原因是在不接受HTTP Request Body的请求中(例如HEAD)设置了不为空的Request Body: \sdk\Common\Communication\netcore\ServiceClientNewImpl.cs Line 173: requestMsg.Content = new System.Net.Http.ByteArrayContent(new byte[0]);

将requestMsg.Content = null就可以了。

burningg commented 3 years ago

@fanruinet @magicjefflee 嗯 同样的问题,但是阿里云还没有更新这个bug?

huiguangjun commented 3 years ago

已经提交到 https://github.com/aliyun/aliyun-oss-csharp-sdk/commit/1c7cf72c770cbf3fde45e14db7a7229c9c2c2e6b

下个版本修复。