apache - 411 error during http post request in java -
i'am facing 411 error during http post request here code. unable find made mistake.i have set content-length though giving same error.
public map<string, string> getaccesstokens(string yahclientid, string yahclientsceret, string yahredirecturl, string authorizationcode) { map<string, string> accesstokens = new hashmap(); string url = "https://api.login.yahoo.com/oauth2/get_token"; final string authinfo = yahclientid + ":" + yahclientsceret; byte[] encodedbytes = base64.decodebase64(authinfo.getbytes()); string postdata = "grant_type=authorization_code&redirect_uri=" + yahredirecturl + "&code=" + authorizationcode; byte[] ascii = postdata.getbytes(standardcharsets.utf_8); try{ httpsurlconnection uc = null; inputstream = null; outputstream osw = null; url u = new url(url); uc = (httpsurlconnection) u.openconnection(); uc.setdoinput(true); uc.setrequestmethod("post"); uc.setrequestproperty("content-length",""+ postdata.getbytes().length); uc.setrequestproperty("content-type", "application/x-www-form-urlencoded"); uc.setdooutput(true); uc.setrequestproperty("authorization", "basic " +new string(new base64().encode(authinfo.getbytes()))); uc.connect(); int responsecode = uc.getresponsecode(); osw = uc.getoutputstream(); uc.getresponsemessage(); osw.write(ascii); osw.flush(); osw.close(); }catch(exception ex){ logger.error(ex); }
wiki
Comments
Post a Comment