【问题标题】:Android ICS SOAP Method Not Working?Android ICS SOAP 方法不起作用?
【发布时间】:2012-08-22 15:51:35
【问题描述】:

我在 samsung galaxy tab 中测试了 SOAP 方法并且工作正常。

我在 Android 冰淇淋三明治 上测试过的代码相同,但无法正常工作。

下面是我的代码,

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);            
            }

在这段代码中,我像这样打印了 httpResponse.getStatusLine().toString() 打印值 HTTP/1.1 200 OK 代码 200

但行值变为空。

谢谢。

【问题讨论】:

    标签: android soap xml-parsing


    【解决方案1】:

    试试这个,

    StrictMode.ThreadPolicy 策略 = new StrictMode.ThreadPolicy.Builder().permitAll().build(); StrictMode.setThreadPolicy(policy);

    【讨论】:

    • 在调用网络相关函数之前。最好使用下面的主类声明。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-07-04
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多