我有一个朋友编写了一个只提供 XML 的 servlet(只是 XML,没有 SOAP 等Content-Type: text/xml
)。
现在我正在尝试使用 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?就像那里有一个特定的标签,比如标题,消息,......