Domanda

Ho bisogno di codificare i params a isolatin che intendo inviare al sito. Sto utilizzando org.apache.http. librerie. Il mio codice si presenta come segue:

HttpClient client = new DefaultHttpClient();

HttpPost post = new HttpPost("www.foobar.bar");
post.setHeader("Content-Type", "application/x-www-form-urlencoded");           
HttpParams params = new BasicHttpParams();

params.setParameter("action", "find");
params.setParameter("what", "somebody");

post.setParams(params);

HttpResponse response2 = httpClient.execute(post);

Grazie!

È stato utile?

Soluzione

si stanno impostando i parametri sbagliati. Ecco un esempio,

       PostMethod method = new PostMethod(url);
       method.addParameters("action", "find");
       method.addParameters("what", "somebody");

       int status = httpClient.executeMethod(method);
       byte[] bytes = method.getResponseBody();
       response = new String(bytes, "iso-8859-1");
       if (status != HttpStatus.SC_OK)
             throw new IOException("Status code: " + status + " Message: "
                                        + response);

La codifica predefinita sarà Latin-1.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top