android - Invalid URL in Paypal Basic access authentication -


hi , thank help.

from android app try paypal oauth refresh_token.

the curl code is:

curl 'https://api.paypal.com/v1/oauth2/token' \ -h "content-type: application/x-www-form-urlencoded" \ -h "authorization: basic qwzv...==" \ -d 'grant_type=authorization_code&response_type=token&redirect_uri=urn:ietf:wg:oauth:2.0:oob&code=ebyhrw3ncivudqn8uoplp4a28...' 

i this.

httpclient httpclient = new defaulthttpclient(); httppost httppost = new httppost("https://api.sandbox.paypal.com/v1/oauth2/token");  try { string text=config_client_id+":"+secret;         byte[] data = text.getbytes("utf-8");         string base64 = base64.encodetostring(data, base64.default);          httppost.addheader("content-type", "application/x-www-form-urlencoded");         httppost.addheader("authorization", "basic "+base64);          stringentity se=new stringentity("grant_type=authorization_code&response_type=token&redirect_uri=urn:ietf:wg:oauth:2.0:oob&code="+authorization.getauthorizationcode());         httppost.setentity(se);  // execute http post request httpresponse response = httpclient.execute(httppost);  } catch (clientprotocolexception e) { // todo auto-generated catch block } catch (ioexception e) { // todo auto-generated catch block } 

but following response:

invalid url

the requested url "/v1/oauth2/token", invalid.


edit edit edit edit edit edit edit

if use

httppost httppost = new httppost("https://api.sandbox.paypal.com") 

i get:

invalid url

the requested url "/", invalid.

reference #9.8c5e6cc1.1395837240.16f01684


edit edit edit edit edit edit edit

the following code seems working,

thanks sabuj hassan answer.

httpclient httpclient = new defaulthttpclient(); httppost httppost = new httppost("https://api.sandbox.paypal.com/v1/oauth2/token");  try { string text=config_client_id+":"+secret;         byte[] data = text.getbytes("utf-8");         string base64 = base64.encodetostring(data, base64.no_wrap);          httppost.addheader("content-type", "application/x-www-form-urlencoded");         httppost.addheader("authorization", "basic "+base64);          stringentity se=new stringentity("grant_type=authorization_code&response_type=token&redirect_uri=urn:ietf:wg:oauth:2.0:oob&code="+authorization.getauthorizationcode());         httppost.setentity(se);  // execute http post request httpresponse response = httpclient.execute(httppost);  } catch (clientprotocolexception e) { // todo auto-generated catch block } catch (ioexception e) { // todo auto-generated catch block } 

but following response paypal sandbox server:

{"error":"invalid_request","error_description":"invalid auth code"} 

your code seems ok me. can send data hosted server nicely. suspect problem following line:

string base64 = base64.encodetostring(data, base64.default); 

print base64 , see whether exact match of header curl's command. want believe different. possibly added newline character(in base64).

so use one:

string base64 = base64.encodetostring(data, base64.no_wrap); 

see documentation other encoding flags.


Comments

Popular posts from this blog

android - Get AccessToken using signpost OAuth without opening a browser (Two legged Oauth) -

org.mockito.exceptions.misusing.InvalidUseOfMatchersException: mockito -

google shop client API returns 400 bad request error while adding an item -