2012-08-28 26 views
6

Tôi đã thử nghiệm phương pháp SOAP trong tab galaxy galaxy và hoạt động tốt.Phương pháp SOAP của Android ICS không hoạt động?

cùng mã tôi đã thử nghiệm trên Bánh kem kẹp Android và không hoạt động.

Dưới đây là Mã của tôi,

HttpPost httppost = new HttpPost("xxxxxx");   
      httppost.setHeader("Content-type", "text/xml; charset=utf-8"); 
      httppost.setHeader("SOAPAction", SoapAction); 

      StringEntity se1 = new StringEntity(env,HTTP.UTF_8); 
      se1.setContentType("text/xml"); 
      se1.setContentEncoding(new BasicHeader(HTTP.CONTENT_TYPE, "text/xml; charset=utf-8")); 
      httppost.setEntity(se1); 

      HttpClient httpclient = new DefaultHttpClient(); 
      BasicHttpResponse httpResponse = (BasicHttpResponse) httpclient.execute(httppost); 

      System.out.println("res------"+httpResponse.getStatusLine().toString()+" code "+httpResponse.getStatusLine().getStatusCode()); 

      //Checking response 
      if(httpResponse!=null){ 
       inputStream = httpResponse.getEntity().getContent(); 


       BufferedReader r = new BufferedReader(new InputStreamReader(inputStream)); 
       StringBuilder total = new StringBuilder(); 
       String line=""; 
       try { 
        while ((line = r.readLine()) != null) { 
         total.append(line); 
        } 
       } catch (IOException e) { 
        // TODO Auto-generated catch block 
        e.printStackTrace(); 
       } 
       System.out.println("line----"+line);    
      } 

Trong mã này tôi in httpResponse.getStatusLine(). ToString() giá trị in như thế này HTTP/1.1 200 OK mã 200

nhưng giá trị dòng nhận được null.

cảm ơn. ..

Trả lời

0

Hãy thử điều này,

chính sách StrictMode.ThreadPolicy = new StrictMode.ThreadPolicy.Builder() permitAll() xây dựng(); StrictMode.setThreadPolicy (chính sách);

+0

nơi tôi nên sử dụng mã này trong dự án của mình ... ??? – Jeeva123

+0

Trước khi gọi các chức năng liên quan đến mạng. Tốt hơn nên sử dụng khai báo dưới đây của lớp chính. – chain

Các vấn đề liên quan