title: Http response gives status "Bad Request" Xamarin.Android
body: <p>I am trying to call a web service by making a Http REST call. But I get a "Bad Request" status in the response. I know this means I have something going wrong with my syntax for the request, but I am unable to find it out.</p>
  
  <p>Here is my code:-</p>
  
  <pre><code>public void GetToken ()
          {
              HttpWebRequest hwr =(HttpWebRequest) WebRequest.Create(string.Format("https://login.windows.net/{0}/oauth2/token", myApp.DomainName));
              hwr.Method = "POST";
              hwr.ContentType = "myApplication/x-www-form-urlencoded";
              hwr.BeginGetRequestStream(new AsyncCallback(SendTokenEndpointRequest), hwr);
          }
  
          protected void SendTokenEndpointRequest (IAsyncResult rez)
          {
              HttpWebRequest hwr = (HttpWebRequest)rez.AsyncState;   
              byte[] bodyBits = Encoding.UTF8.GetBytes(
                  string.Format(
                      "grant_type=authorization_code&amp;code={0}&amp;client_id={1}&amp;redirect_uri={2}",
                      myApp.Code, 
                      myApp.ClientId, 
                      HttpUtility.UrlEncode(myApp.RedirectUri)));
              Stream st = hwr.EndGetRequestStream(rez);
              st.Write(bodyBits, 0, bodyBits.Length);
              st.Close();
              hwr.BeginGetResponse(new AsyncCallback(RetrieveTokenEndpointResponse), hwr);
          }
  
          public void RetrieveTokenEndpointResponse (IAsyncResult rez)
          {
              HttpWebRequest hwr =(HttpWebRequest) rez.AsyncState;
              HttpWebResponse resp =(HttpWebResponse)hwr.EndGetResponse(rez); // ERROR HERE
  
              StreamReader sr = new StreamReader(resp.GetResponseStream());
              string responseString = sr.ReadToEnd();
              JObject jo = JsonConvert.DeserializeObject(responseString) as JObject;
              myApp.AccessToken = (string)jo["access_token"];
  
  
              System.Threading.Thread myThread = new  System.Threading.Thread (() =&gt; 
              {
                      ma.myWebView.GoBack ();
              });
              myThread.Start ();
          }
  </code></pre>
  
  <p>Any suggestions are appreciated. Thanks.</p>