Java ile Google OAuth 2.0 çevresinde çalışıyorum ve uygulama sırasında bilinmeyen bir hatayla karşılaştım.Bu POST isteği uygulamasında sorun nedir?
curl -v -k --header "Content-Type: application/x-www-form-urlencoded" --data "code=4%2FnKVGy9V3LfVJF7gRwkuhS3jbte-5.Arzr67Ksf-cSgrKXntQAax0iz1cDegI&client_id=[my_client_id]&client_secret=[my_client_secret]&redirect_uri=[my_redirect_uri]&grant_type=authorization_code" https://accounts.google.com/o/oauth2/token
Ve istenilen sonucu üretir:
POST isteği için aşağıdaki CURL gayet iyi çalışıyor.
Ama java yukarıdaki POST isteğinin aşağıdaki uygulama bazı hata ve aşağıdaki kod ve nokta sorun ne burada olacak "invalid_request"
Giriş tepkisini neden olur: (Apache yapılmış kullanımı http-bileşenler)
HttpPost post = new HttpPost("https://accounts.google.com/o/oauth2/token");
HttpParams params = new BasicHttpParams();
params.setParameter("code", code);
params.setParameter("client_id", client_id);
params.setParameter("client_secret", client_secret);
params.setParameter("redirect_uri", redirect_uri);
params.setParameter("grant_type", grant_type);
post.addHeader("Content-Type", "application/x-www-form-urlencoded");
post.setParams(params);
DefaultHttpClient httpClient = new DefaultHttpClient();
HttpResponse response = httpClient.execute(post);
ile çalıştı Her parametre için URLEncoder.encode(param , "UTF-8")
, ancak bu da çalışmıyor.
Sebep ne olabilir?
Bu yardımcı oldu !! –