title: HttpWebRequest method GET/POST not working?
body: <p>I am working with GoogleApi. I want to get accesstoken as response using Google api. when I am sending httpwebrequest for getting access token then</p>
  
  <p>When I used :- request.Method = "POST"</p>
  
  <p>Exception:- HTTP method POST is not supported by this URL</p>
  
  <p>When I used :- request.Method = "GET"</p>
  
  <p>Exception:- System.Net.ProtocolViolationException: Cannot send a content-body with this verb-type</p>
  
  <p>The actual request might look like: </p>
  
  <pre><code>POST /o/oauth2/token HTTP/1.1
  Host: accounts.google.com
  Content-Type: application/x-www-form-urlencoded
  
  code=4/P7q7W91a-oMsCeLvIaQm6bTrgtp7&amp;
  client_id=8819981768.apps.googleusercontent.com&amp;
  client_secret={client_secret}&amp;
  redirect_uri=https://oauth2-login-demo.appspot.com/code&amp;
  grant_type=authorization_code
  </code></pre>
  
  <p>A successful response is returned as a JSON array, similar to the following:</p>
  
  <pre><code>{
    "access_token":"1/fFAGRNJru1FTz70BzhT3Zg",
    "expires_in":3920,
    "token_type":"Bearer"
  </code></pre>
  
  <p>}</p>
  
  <p>My Code is :-</p>
  
  <pre><code>    var request = (HttpWebRequest)WebRequest.Create(@"https://accounts.google.com");
      request.Method = "POST";
      request.ContentType = "application/json";
      //request.KeepAlive = false;
  
      // request.Headers[HttpRequestHeader.Authorization] = "";
      //request.ContentLength = 0;
  
      using (StreamWriter streamWriter = new StreamWriter(request.GetRequestStream()))
      {
          string json = "{\"code\":\"4/M1IIC8htCuvYORuVJK16oadDb3Gd.cigIKgaPjvUYXE-sT2ZLcbSrckCLgwI\"," + "\"client_id\":\"841994137170.apps.googleusercontent.com\"," + "\"client_secret\":\"MXjKvevD_cKp5eQWZ1RFXfdo\"," + "\"redirect_uri\":\"http://gmailcheck.com/response.aspx\"," + "\"grant_type\":\"authorization_code\"}";
  
          streamWriter.Write(json);
          // streamWriter.Flush();
          //streamWriter.Close();
      }
      try
      {
          using (HttpWebResponse response = (HttpWebResponse)request.GetResponse())
          {
              StreamReader responsereader = new StreamReader(response.GetResponseStream());
  
              var responsedata = responsereader.ReadToEnd();
              //Session["responseinfo"] = responsereader;     
          }
      }
      catch (WebException ex)
      {
          using (WebResponse response = ex.Response)
          {
              var httpResponse = (HttpWebResponse)response;
  
              using (Stream data = response.GetResponseStream())
              {
                  var sr = new StreamReader(data);
                  throw new Exception(sr.ReadToEnd());
              }
          }
      }
  </code></pre>