Richtige Weg, um einen HTTP-request in Android

Welches ist der beste Weg, um eine HTTP-Verbindung. Ich meine, mit proxies und so weiter. Jetzt bin ich mit dieser hier:

StringBuilder entity = new StringBuilder();
entity.append("request body");

AndroidHttpClient httpClient = AndroidHttpClient.newInstance(null);

String proxyHost = android.net.Proxy.getDefaultHost();
int proxyPort = android.net.Proxy.getDefaultPort();
if (proxyHost != null && proxyPort > 0) {
    HttpHost proxy = new HttpHost(proxyHost, proxyPort);
    ConnRouteParams.setDefaultProxy(httpClient.getParams(), proxy);
}
HttpPost httpPost = new HttpPost("https://w.qiwi.ru/term2/xmlutf.jsp");
httpPost.setEntity(new StringEntity(entity.toString(), "UTF-8"));
httpPost.setHeader("Content-Type", "application/x-www-form-urlencoded");
HttpParams params = new BasicHttpParams();
HttpConnectionParams.setConnectionTimeout(params, 15000);
HttpConnectionParams.setSoTimeout(params, 30000);
httpPost.setParams(params);
HttpResponse httpResponse = httpClient.execute(httpPost);

int responseCode = httpResponse.getStatusLine().getStatusCode();
if (responseCode == HttpStatus.SC_OK) {
    //parsing response
}

Ich bin mir nicht wirklich sicher, ob das ok ist, weil einer meiner Kunden sagt mir, er hat eine IllegalArgumentException rechts nach Einstellung proxy in seinem APN-Einstellungen.

  • Ich verwende diesen code in AsyncTask
  • Ich habe nicht gefunden, einen Einsatz von proxies gibt. Was ist, wenn in Ihr android-Handy wäre da ein proxy in deine APN-Einstellungen?
  • Sorry, keine Idee... 🙁
InformationsquelleAutor nixan | 2011-09-27
Schreibe einen Kommentar