java - Retrieving dynamic JSONObject value from server response in servlets -


hi getting access_token value dynamically server servlet request below: want retrive access_taken value in servlet program.

{     "access_token":"aqwp_evkqdc7e0wd09j6msmjnulvilhp304guidzl6kkgnxwnhyz_w9noxs0irodjwefvr3n3o-ic9ykc3bjyuwyrm6qbkrip3a2azudjo8ohzerzfrcmyfjjqqdjnj5j5recqdhkfjam51eiqsoexdg4u_c9xjzc1dux7qxck0p9rne0",     "expires_in": 5183999 } 

my code below:

public class demo extends httpservlet { private static final long serialversionuid = 1l; private static final string protected_resource_url = "http://api.linkedin.com/v1/people/~:(first-name,last-name,email-address)";  /**  * @see httpservlet#httpservlet()  */ public demo() {     super();     // todo auto-generated constructor stub }  /**  * @see httpservlet#doget(httpservletrequest request, httpservletresponse response)  */ protected void doget(httpservletrequest request, httpservletresponse response) throws servletexception, ioexception  {     printwriter out=response.getwriter();     string authcode = request.getparameter("code");     request.setattribute("authcode",authcode);     out.println(authcode);     dopost(request,response); }  /**  * @see httpservlet#dopost(httpservletrequest request, httpservletresponse response)  */ protected void dopost(httpservletrequest request, httpservletresponse response) throws servletexception, ioexception  {     printwriter out=response.getwriter();     object url=request.getattribute("authcode");     response.sendredirect("https://www.linkedin.com/uas/oauth2/accesstoken?grant_type=authorization_code&code="+url+"&redirect_uri=http://localhost:8080/linkedinmails/dem&client_id=xxxxxxxxxxxxx&client_secret=xxxxxxxxxxxxxxx");  } 

}

thank you.

    public string doget(string url) throws exception {       url urlobj = new url(url);     httpurlconnection conn = (httpurlconnection) urlobj.openconnection();     conn.setdooutput(true);      string line;     stringbuffer buffer = new stringbuffer();     bufferedreader reader = new bufferedreader(new inputstreamreader(             conn.getinputstream()));      while ((line = reader.readline()) != null) {         buffer.append(line);     }      reader.close();     conn.disconnect();      return buffer.tostring(); } 

now can call method servlet server response in servlet. hope useful you.


Comments

Popular posts from this blog

matlab - "Contour not rendered for non-finite ZData" -

delphi - Indy UDP Read Contents of Adata -

javascript - Any ideas when Firefox is likely to implement lengthAdjust and textLength? -