Tôi có mã ứng dụng Android sau đây. Tôi đang cố gắng kết nối với một dịch vụ web thông qua HTTP. Dịch vụ web sử dụng trục apache. Tuy nhiên tôi đang chạy vào lỗi "Lỗi đọc XMLStreamReader" trong phản hồi. Tôi thực sự bị mắc kẹt và không chắc chắn những gì tôi có thể làm. Có thể nào là có các phiên bản khác nhau của HTTP client và SOAP đang được sử dụng trên máy chủ và phía máy khách? Bất kì sự giúp đỡ nào trong việc này đều rất được trân trọng. Dịch vụ web rất đơn giản: phương thức sayHello hiển thị đối số được đưa ra trong arg0 = some_stringLỗi đáp ứng phong bì SOAP: Lỗi khi đọc XMLStreamReader
public class MainActivity extends Activity {
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.activity_main, menu);
return true;
}
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
StrictMode.setThreadPolicy(policy);
BufferedReader in = null;
try {
HttpClient client = new DefaultHttpClient();
HttpPost request = new HttpPost(
"http://10.0.0.63:8080/archibus/cxf/HelloWorld/sayHello");
request.addHeader("Content-Type", "text/xml");
List<NameValuePair> postParameters = new ArrayList<NameValuePair>();
postParameters.add(new BasicNameValuePair("arg0", "testing"));
UrlEncodedFormEntity formEntity = new UrlEncodedFormEntity(postParameters);
request.setEntity(formEntity);
HttpResponse response = client.execute(request);
in = new BufferedReader(new InputStreamReader(response.getEntity().getContent()));
StringBuffer sb = new StringBuffer("");
String line = "";
String NL = System.getProperty("line.separator");
while ((line = in.readLine()) != null) {
sb.append(line + NL);
}
in.close();
String page = sb.toString();
// Log.i(tag, page);
System.out.println(page);
} catch (Exception e) {
e.printStackTrace();
} finally {
if (in != null) {
try {
in.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
}
}
http://www.lalit3686.blogspot.in/2012/06/calling-soap-webservice-using- httppost.html –