我有一個朋友寫了一個servlet,它只是提供XML(只是XML,沒有SOAP等,Content-Type: text/xml
)。android與網頁溝通,得到502錯誤
現在我試圖使用android訪問它。如果我使用Firefox瀏覽頁面,我可以訪問該頁面,但如果使用我的Android應用程序訪問它,我會得到一個HTTP 502 error
。
我正在使用的代碼是:
AlertDialog alertDialog;
HttpClient httpClient = new DefaultHttpClient();
HttpContext localContext = new BasicHttpContext();
HttpGet httpGet = new HttpGet("x");
try {
HttpResponse response = httpClient.execute(httpGet, localContext);
alertDialog = new AlertDialog.Builder(view.getContext()).create();
alertDialog.setButton("OK", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
return;
}
});
alertDialog.setTitle("Response");
alertDialog.setMessage(response.getStatusLine().toString());
alertDialog.show();
alertDialog.setMessage(EntityUtils.toString(response.getEntity()));
alertDialog.show();
} catch (IOException e) {
alertDialog = new AlertDialog.Builder(view.getContext()).create();
alertDialog.setTitle("Sorry");
alertDialog.setMessage("There was a problem connecting to the login-service.");
alertDialog.setButton("OK", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
return;
}
});
alertDialog.show();
}
以及是否有任何建議的方式來解析XML?就像是如果有一個特定的標籤,如標題,消息,...