我正在尝试上班。它适用于邮差,但它不适用于我的应用程序。 它似乎达到了超时。
jbx.sellos.com.br/v1/auth
我正在使用此代码:
public async void GetToken(string strUserName, string strPassword)
{
var client = new HttpClient();
object userInfo = new { username = "root", password = "toor" };
var jsonObj = JsonConvert.SerializeObject(userInfo);
var content = new StringContent(jsonObj, Encoding.UTF8, "application/json");
HttpResponseMessage response = client.PostAsync(RequestUri(), content).Result;
var result = await response.Content.ReadAsStringAsync();
}
这是我尝试过的另一个代码:
public async Task<bool> Test()
{
HttpClient client = new HttpClient();
object userInfo = new { username = "root", password = "toor" };
var jsonObj = JsonConvert.SerializeObject(userInfo);
var content = new StringContent(jsonObj, Encoding.UTF8, "application/json");
try
{
HttpResponseMessage response = await client.PostAsync(RequestUri(), content);
var result = await response.Content.ReadAsStringAsync();
if (response.IsSuccessStatusCode)
{
return true;
}
return false;
}
catch (Exception e)
{
return false;
}
}
在所有情况下,代码运行到HttpResponseMessage response = await client.PostAsync(RequestUri(), content);
之后,应用程序继续运行但过了一会儿我收到一条消息“应用程序处于中断模式”。
因此,在深入挖掘之后,我能够捕获异常:
{System.Threading.Tasks.TaskCanceledException: A task was canceled.
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess (System.Threading.Tasks.Task task) [0x00026] in <3fd174ff54b146228c505f23cf75ce71>:0
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification (System.Threading.Tasks.Task task) [0x00028] in <3fd174ff54b146228c505f23cf75ce71>:0
at System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd (System.Threading.Tasks.Task task) [0x00008] in <3fd174ff54b146228c505f23cf75ce71>:0
at System.Runtime.CompilerServices.TaskAwaiter`1[TResult].GetResult () [0x00000] in <3fd174ff54b146228c505f23cf75ce71>:0
at System.Net.Http.HttpClientHandler+<SendAsync>d__63.MoveNext () [0x004c6] in <b696532a7c264e5e866cb15a1b40a4a4>:0
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw () [0x0000c] in <3fd174ff54b146228c505f23cf75ce71>:0
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess (System.Threading.Tasks.Task task) [0x0001a] in <3fd174ff54b146228c505f23cf75ce71>:0
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification (System.Threading.Tasks.Task task) [0x00028] in <3fd174ff54b146228c505f23cf75ce71>:0
at System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd (System.Threading.Tasks.Task task) [0x00008] in <3fd174ff54b146228c505f23cf75ce71>:0
at System.Runtime.CompilerServices.ConfiguredTaskAwaitable`1+ConfiguredTaskAwaiter[TResult].GetResult () [0x00000] in <3fd174ff54b146228c505f23cf75ce71>:0
at System.Net.Http.HttpClient+<SendAsyncWorker>d__49.MoveNext () [0x000ca] in <b696532a7c264e5e866cb15a1b40a4a4>:0
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw () [0x0000c] in <3fd174ff54b146228c505f23cf75ce71>:0
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess (System.Threading.Tasks.Task task) [0x0001a] in <3fd174ff54b146228c505f23cf75ce71>:0
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification (System.Threading.Tasks.Task task) [0x00028] in <3fd174ff54b146228c505f23cf75ce71>:0
at System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd (System.Threading.Tasks.Task task) [0x00008] in <3fd174ff54b146228c505f23cf75ce71>:0
at System.Runtime.CompilerServices.ConfiguredTaskAwaitable`1+ConfiguredTaskAwaiter[TResult].GetResult () [0x00000] in <3fd174ff54b146228c505f23cf75ce71>:0
at AppX.WebServiceCalls+<SendRequestAsync>d__3.MoveNext () [0x000ba] in C:\Users\Bruno\documents\visual studio 2017\Projects\AppX\AppX\AppX\clWebServiceCalls.cs:123 }
我发现这些人谈论类似的东西: https://github.com/dotnet/corefx/issues/25800
到目前为止,还没有找到解决方案的线索。
答案 0 :(得分:4)
由于
,您似乎陷入僵局case class obja = (a_id: String, a_type: String)
case class objb = (b_id: String, b_type: String, b_name: String)
case class objc = (c_id: String, c_type: String, c_name: String)
val lista: List[obja] = List(...)
val listb: List[objb] = List(...)
def getNames(alist: List[obja], blist: List[objb]): List[objc] = ???
您应该将def r(x: Int, y: Int): Int =
if (x==y) x
else if (x>y) r(x-y, y)
else r(x, y-x)
用于异步方法。所以,修改那一行;
HttpResponseMessage response = client.PostAsync(RequestUri(), content).Result;
答案 1 :(得分:0)
解决方案:
var client = new HttpClient(new NativeMessageHandler());
这是我必须更改的所有代码new NativeMessageHandler()
。
我还在我的解决方案中添加了一个包。搜索“modernhttpclient”。
感谢大家的帮助。