title: The remote server returned an error: (400) Bad Request. When try to login with facebook in asp.net
body: <p>I am try to login with a user with Facebook account in my website, but the applcation gives me error that The remote server returned an error: (400) Bad Request. </p>
  
  <p>Below is my code:</p>
  
  <pre><code>public string WebRequest(Method method, string url, string postData)
  {
  
      HttpWebRequest webRequest = null;
      StreamWriter requestWriter = null;
      string responseData = "";    
  
      webRequest = System.Net.WebRequest.Create(url) as HttpWebRequest;
      webRequest.Method = method.ToString();
      webRequest.ServicePoint.Expect100Continue = false;
      webRequest.UserAgent = "[You user agent]";
      webRequest.Timeout = 50000;
  
  
      if (method == Method.POST)
      {
          webRequest.ContentType = "application/x-www-form-urlencoded";
  
          //POST the data.
          requestWriter = new StreamWriter(webRequest.GetRequestStream());
  
          try
          {
              requestWriter.Write(postData);
          }
          catch
          {
              throw;
          }
  
          finally
          {
              requestWriter.Close();
              requestWriter = null;
          }
      }
  
      responseData = WebResponseGet(webRequest);
      webRequest = null;
      return responseData;
  }
  </code></pre>
  
  <p>*<strong><em>It gives me error in this method:</em>*</strong></p>
  
  <pre><code> public string WebResponseGet(HttpWebRequest webRequest)
  {
      StreamReader responseReader = null;
      string responseData = "";
  
      try
      {
          responseReader = new      StreamReader(webRequest.GetResponse().GetResponseStream());
          responseData = responseReader.ReadToEnd();
      }
      catch
      {
          throw;
      }
      finally
      {
          webRequest.GetResponse().GetResponseStream().Close();
          responseReader.Close();
          responseReader = null;
      }
  
      return responseData;
  }
  </code></pre>