xml从android应用程序发送到ip:端口

时间:2014-04-12 10:01:46

标签: android xml androidhttpclient

我创建了一个Android应用程序,它会将xml数据发送到特定的ip:port。代码运行良好,没有任何错误或警告。

但我们如何确定发送xml将正确到达ip:端口。如果有任何方法可以识别数据是否正确到达端口。

我的代码如下。

 //xml sending


DefaultHttpClient httpClient = new DefaultHttpClient();

HttpPost httppost = new HttpPost("http://10.0.2.2:9900/");     
// Make sure the server knows what kind of a response we will accept
httppost.addHeader("Accept", "text/xml");
// Also be sure to tell the server what kind of content we are sending
httppost.addHeader("Content-Type", "application/xml");

try
{
//xmlString is my xml data
StringEntity entity = new StringEntity(xmlString, "UTF-8");
entity.setContentType("application/xml");
httppost.setEntity(entity);

new Thread(new Runnable() {
        public void run() {
             // execute is a blocking call, it's best to call this code in a thread separate from the ui's
            try {
                response = httpClient.execute(httppost);
            } catch (ClientProtocolException e) {
                // TODO Auto-generated catch block
                Log.e("message",Log.getStackTraceString(e));
            } catch (IOException e) {
                // TODO Auto-generated catch block
                Log.e("message",Log.getStackTraceString(e));
            }
                }
            }).start(); 



      BasicResponseHandler responseHandler = new BasicResponseHandler();
       String strResponse = null;
       if (response != null) {
           try {
               strResponse = responseHandler.handleResponse(response);
           } catch (HttpResponseException e) {
               Log.e("message",Log.getStackTraceString(e));
           } catch (IOException e) {
               Log.e("message",Log.getStackTraceString(e));
           }
       }
       Log.e("WCFTEST", "WCFTEST ********** Response" + strResponse);    


    }
    catch (Exception ex)
    {
   // ex.printStackTrace();
        Log.e("message",Log.getStackTraceString(ex));
    Toast.makeText(OrderlistActivity.this, ex.getMessage(),Toast.LENGTH_SHORT).show();
    }
    Toast.makeText(OrderlistActivity.this, "Xml posted succesfully.",Toast.LENGTH_SHORT).show();

}
  } 
logcat中只有“无响应”消息。但是我们如何识别端口是否已达到数据

0 个答案:

没有答案