Click here to Skip to main content
15,887,341 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Sending request on this link, but getting bad request .Please Help..
https://accounts.google.com/o/oauth2/token?code=[code]&grant_type=authorization_code&client_id=[clientId]&client_secret=[clientSecret]&redirect_uri=http://localhost:52731/Common/Index[^]

C#
string code = Request.QueryString["code"];
                   string con= "?code=" + code +
                   "&grant_type=" + "authorization_code" +
                   "&client_id=" + TokenData.GoogleAppKey +
                   "&client_secret=" + TokenData.GoogleAppSecret +
                   "&redirect_uri=" + "http://localhost:52731/Common/Index";
                   var req = (HttpWebRequest)WebRequest.Create(TokenData.GoogleTokenUrl + con);
                   req.Method = "POST";
                   req.ContentType = "application/x-www-form-urlencoded";
                   req.ContentLength = 0;

                   var a = req.GetResponse();


Here is a Response:
The remote server returned an error: (400) Bad Request.
Posted
Updated 24-Nov-15 2:34am
v3
Comments
xszaboj 24-Nov-15 8:37am    
is your url encoded correctly?
Adil Liaqat 24-Nov-15 8:43am    
https://accounts.google.com/o/oauth2/token?code=[code]&grant_type=authorization_code&client_id=[clientId]&client_secret=[clientSecret]&redirect_uri=http://localhost:52731/Common/Index this is the url that i m sending in webrequest.create(url); is there any thing i m missing?
xszaboj 24-Nov-15 9:48am    
well if for example code will be "abcd+efg" you need to url-encode it. Because + means space in url wich is something you dont want. But I don't know if that is your case :). Might be something completly different, but it was first thing on my mind to check.
Kornfeld Eliyahu Peter 24-Nov-15 9:01am    
When I'm running your post I receive an 411 error - POST requests require a Content-length header
LoboMan 16-Dec-15 15:13pm    
...and, I got a 405 - Method Not Alllowed

Something is definitely fishy.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900