大家好,我正在尝试使用 silverlight 5 发送 getasync 请求。后异步工作没有任何问题,但是 getasync 在添加授权标头时抛出该异常。当不添加授权标头时,这无一例外只是 401。我应该怎么做才能修复它?
编码:
client.DefaultRequestHeaders.Add("Authorization", "Bearer secrettoken");
var getasynctask = await client.GetAsync("http://api.enteroption.com/api/UserDetails/GetUserIdByToken/");
例外:
System.ArgumentException occurred
Message=""
StackTrace:
at Microsoft.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at Microsoft.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccess(Task task)
at Microsoft.Runtime.CompilerServices.TaskAwaiter.ValidateEnd(Task task)
at Microsoft.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
at ConsoleApplication3.Class1.<Func>d__1.MoveNext()
InnerException: System.ArgumentException
Message=Value does not fall within the expected range.
StackTrace:
at System.Net.Browser.BrowserHttpWebRequest.InternalEndGetResponse(IAsyncResult asyncResult)
at System.Net.Browser.BrowserHttpWebRequest.<>c__DisplayClassa.<EndGetResponse>b__9(Object sendState)
at System.Net.Browser.AsyncHelper.<>c__DisplayClass4.<BeginOnUI>b__0(Object sendState)
InnerException: