I am trying to setup github with membership reboot.
If I try calling the github api from a browser like
https://api.github.com/user?access_token=XXXXXXX
I can see all the valid json data however if I try from .net
public ActionResult Index()
{
var url = "https://api.github.com/user?access_token=XXXXXXXX";
////add additional params
//if (additionalParams != null)
//{
// foreach (string key in additionalParams)
// {
// url += string.Format("&{0}={1}", key, additionalParams[key]);
// }
//}
HttpClient client = new HttpClient();
var result = client.GetAsync(url).Result;
if (result.IsSuccessStatusCode)
{
var json = result.Content.ReadAsStringAsync().Result;
var profile = Newtonsoft.Json.JsonConvert.DeserializeObject<Dictionary<string, object>>(json);
//return GetClaimsFromProfile(profile);
}
return View();
}
I get an error of
The server committed a protocol violation. Section=ResponseStatusLine
What doesn't HttpClient like about what I am trying? Do I need to provide extra details that the browser is doing for me?
Any help would be appreciated!
Adding
<system.net>
<settings>
<httpWebRequest useUnsafeHeaderParsing="true" />
</settings>
</system.net>
to my web.config seems to solve the problem...I dont really understand why I needed to add this but it works.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With