hc-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Hendy Irawan (Commented) (JIRA)" <j...@apache.org>
Subject [jira] [Commented] (HTTPCLIENT-1175) URLEncodedUtils.parse(HttpEntity) not working if Content-Encoding is not specified
Date Tue, 20 Mar 2012 07:19:38 GMT

    [ https://issues.apache.org/jira/browse/HTTPCLIENT-1175?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13233280#comment-13233280
] 

Hendy Irawan commented on HTTPCLIENT-1175:
------------------------------------------

Thank you Oleg ! Much appreciated :)
                
> URLEncodedUtils.parse(HttpEntity) not working if Content-Encoding is not specified
> ----------------------------------------------------------------------------------
>
>                 Key: HTTPCLIENT-1175
>                 URL: https://issues.apache.org/jira/browse/HTTPCLIENT-1175
>             Project: HttpComponents HttpClient
>          Issue Type: Bug
>          Components: HttpClient
>    Affects Versions: 4.1.3, 4.2 Beta1
>            Reporter: Hendy Irawan
>
> The code below does not work :
> 	/**
> 	 * Sets the authCode received from Facebook and exchanges it with the access token.
> 	 * @param authCode
> 	 * @throws IOException 
> 	 * @throws ClientProtocolException 
> 	 */
> 	public void setFacebookAuthCode(String authCode) throws ClientProtocolException, IOException
{
> 		log.info("Retrieving access token using authCode {}", authCode);
> 		URI accessTokenUri = facebookAuth.getAccessTokenUri(authCode);
> 		DefaultHttpClient client = new DefaultHttpClient();
> 		HttpGet accessTokenReq = new HttpGet(accessTokenUri);
> 		HttpResponse response = client.execute(accessTokenReq);
> 		if (response.getStatusLine().getStatusCode() != 200)
> 			throw new IOException(String.format("GET %s throws HTTP Error %d: %s",
> 					accessTokenUri, response.getStatusLine().getStatusCode(), response.getStatusLine().getReasonPhrase()));
> 		// Probably due to non-existing Content-Encoding, this one is not working:
> 		List<NameValuePair> data = URLEncodedUtils.parse(response.getEntity());
> 		setFbAccessToken(data.get(0).getValue());
> 		
> 		log.info("Access token received, redirecting to Post Status page");
> 		ExternalContext external = FacesContext.getCurrentInstance().getExternalContext();
> 		external.redirect(external.encodeActionURL("/faces/post.xhtml"));
> 	}
> I have to use a workaround :
> 		Scanner scanner = new Scanner(response.getEntity().getContent());
> 		ArrayList<NameValuePair> data = new ArrayList<NameValuePair>();
> 		URLEncodedUtils.parse(data, scanner, "UTF-8");
> Expected behavior :
> Should either default to UTF-8 (recommended) or make it an explicit parameter.
> FYI : Code above is taken from FBStatus open source project at https://github.com/soluvas/fbstatus

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators: https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@hc.apache.org
For additional commands, e-mail: dev-help@hc.apache.org


Mime
View raw message