0

Hi guys i am trying to send getasync request with silverlight 5. the post async is working without any problem but the getasync throw that exception when adding authorization header. when not adding authorization header this is without exception just 401. what should i do to fix it?

the code:

    client.DefaultRequestHeaders.Add("Authorization", "Bearer secrettoken");

var getasynctask = await client.GetAsync("http://api.enteroption.com/api/UserDetails/GetUserIdByToken/");

the exception:

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:
User9898
  • 251
  • 1
  • 3
  • 11

1 Answers1

0

i know this is late but i struggled for quite a while with this getting my head wrapped the wrong way round .. but eventually i did the following and it worked, it really annoys me that this was the problem

  client.DefaultRequestHeaders.Add("Authorization", "Bearer " + kvp.Value);
  //client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", kvp.Value );
Barry
  • 171
  • 1
  • 11