使用 Web 客户端的 HTTP 请求。随机错误(验证失败,因为对方关闭了传输流。)
HTTP request with web client. Random error with (Verification failed because the other party has closed the transport stream.)
嘿你好我正在使用 MVC 和 Umbraco 的 atm,我正在尝试使用 webclient http 协议进行 API 调用。
这是我正在做的请求。
[HttpPost]
public JObject CheckAuth()
{
string URI = "https://nedfinity.api.accelo.com/oauth2/v0/token";
string myParameters = "grant_type=client_credentials&scope=read(all)";
var clientId = "this is a secret";
var clientSecret = "this is a secret";
var byteArray = new UTF8Encoding().GetBytes(clientId + ":" + clientSecret);
using (WebClient wc = new WebClient())
{
wc.UseDefaultCredentials = true;
wc.Headers[HttpRequestHeader.ContentType] = "application/x-www-form-urlencoded";
wc.Headers[HttpRequestHeader.Authorization] = "Basic " + Convert.ToBase64String(byteArray);
string HtmlResult = wc.UploadString(URI, myParameters);
JObject json = JObject.Parse(HtmlResult);
return json;
}
}
它过去一直工作得很好,但在我编辑时不知从何而来 CSS 它停止工作了。我试图撤销我在 bitbucket 中的所有提交,但没有修复。
此外,当尝试从 accelo 调用 api 时,它的工作正常。
这是我从服务器得到的唯一反馈:
data
:
Object
ExceptionMessage
:
"Verification failed because the other party has closed the transport stream."
ExceptionType
:
"System.IO.IOException"
Message
:
"An error has occurred."
StackTrace
:
" bij System.Net.Security.SslState.StartReadFrame(Byte[] buffer, Int32 readBytes, AsyncProtocolRequest asyncRequest)
↵ bij System.Net.Security.SslState.StartReceiveBlob(Byte[] buffer, AsyncProtocolRequest asyncRequest)
↵ bij System.Net.Security.SslState.CheckCompletionBeforeNextReceive(ProtocolToken message, AsyncProtocolRequest asyncRequest)
↵ bij System.Net.Security.SslState.StartSendBlob(Byte[] incoming, Int32 count, AsyncProtocolRequest asyncRequest)
↵ bij System.Net.Security.SslState.ForceAuthentication(Boolean receiveFirst, Byte[] buffer, AsyncProtocolRequest asyncRequest)
↵ bij System.Net.Security.SslState.ProcessAuthentication(LazyAsyncResult lazyResult)
↵ bij System.Net.TlsStream.CallProcessAuthentication(Object state)
↵ bij System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
↵ bij System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
↵ bij System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
↵ bij System.Net.TlsStream.ProcessAuthentication(LazyAsyncResult result)
↵ bij System.Net.TlsStream.Write(Byte[] buffer, Int32 offset, Int32 size)
↵ bij System.Net.PooledStream.Write(Byte[] buffer, Int32 offset, Int32 size)
↵ bij System.Net.ConnectStream.WriteHeaders(Boolean async)"
任何人都知道什么会导致此问题以及如何修复它或在哪里查看?
我认为我自己这与某些配置设置或网络权限有关,但它在本地主机上,我这次没有更改任何可能导致此问题的内容。
P.S。我希望这种正确的提问方式,如果有什么不对的地方,请随时指出我。
您能否尝试将安全协议设置为以下内容:
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12
大多数 API 现在使用 TLS12 作为默认协议。
告诉我进展如何。
PS。您可以将其添加到现有方法块中。
此致
克雷格
嘿你好我正在使用 MVC 和 Umbraco 的 atm,我正在尝试使用 webclient http 协议进行 API 调用。
这是我正在做的请求。
[HttpPost]
public JObject CheckAuth()
{
string URI = "https://nedfinity.api.accelo.com/oauth2/v0/token";
string myParameters = "grant_type=client_credentials&scope=read(all)";
var clientId = "this is a secret";
var clientSecret = "this is a secret";
var byteArray = new UTF8Encoding().GetBytes(clientId + ":" + clientSecret);
using (WebClient wc = new WebClient())
{
wc.UseDefaultCredentials = true;
wc.Headers[HttpRequestHeader.ContentType] = "application/x-www-form-urlencoded";
wc.Headers[HttpRequestHeader.Authorization] = "Basic " + Convert.ToBase64String(byteArray);
string HtmlResult = wc.UploadString(URI, myParameters);
JObject json = JObject.Parse(HtmlResult);
return json;
}
}
它过去一直工作得很好,但在我编辑时不知从何而来 CSS 它停止工作了。我试图撤销我在 bitbucket 中的所有提交,但没有修复。 此外,当尝试从 accelo 调用 api 时,它的工作正常。 这是我从服务器得到的唯一反馈:
data
:
Object
ExceptionMessage
:
"Verification failed because the other party has closed the transport stream."
ExceptionType
:
"System.IO.IOException"
Message
:
"An error has occurred."
StackTrace
:
" bij System.Net.Security.SslState.StartReadFrame(Byte[] buffer, Int32 readBytes, AsyncProtocolRequest asyncRequest)
↵ bij System.Net.Security.SslState.StartReceiveBlob(Byte[] buffer, AsyncProtocolRequest asyncRequest)
↵ bij System.Net.Security.SslState.CheckCompletionBeforeNextReceive(ProtocolToken message, AsyncProtocolRequest asyncRequest)
↵ bij System.Net.Security.SslState.StartSendBlob(Byte[] incoming, Int32 count, AsyncProtocolRequest asyncRequest)
↵ bij System.Net.Security.SslState.ForceAuthentication(Boolean receiveFirst, Byte[] buffer, AsyncProtocolRequest asyncRequest)
↵ bij System.Net.Security.SslState.ProcessAuthentication(LazyAsyncResult lazyResult)
↵ bij System.Net.TlsStream.CallProcessAuthentication(Object state)
↵ bij System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
↵ bij System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
↵ bij System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
↵ bij System.Net.TlsStream.ProcessAuthentication(LazyAsyncResult result)
↵ bij System.Net.TlsStream.Write(Byte[] buffer, Int32 offset, Int32 size)
↵ bij System.Net.PooledStream.Write(Byte[] buffer, Int32 offset, Int32 size)
↵ bij System.Net.ConnectStream.WriteHeaders(Boolean async)"
任何人都知道什么会导致此问题以及如何修复它或在哪里查看?
我认为我自己这与某些配置设置或网络权限有关,但它在本地主机上,我这次没有更改任何可能导致此问题的内容。
P.S。我希望这种正确的提问方式,如果有什么不对的地方,请随时指出我。
您能否尝试将安全协议设置为以下内容:
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12
大多数 API 现在使用 TLS12 作为默认协议。
告诉我进展如何。
PS。您可以将其添加到现有方法块中。
此致
克雷格