public static String getAddress (final InputStream inputStream, final String mobile) { Thread thread = new Thread() { public void run() { try { Log. i(TAG, "inputStream: " + inputStream.available()); String soap = readSoapFile(inputStream, mobile); byte[] data = soap.getBytes(); URL url = new URL( "http://webservice.webxml.com.cn/WebServices/MobileCodeWS.asmx" ); HttpURLConnection conn = (HttpURLConnection) url .openConnection(); conn.setDoOutput( true); conn.setConnectTimeout(5 * 1000); conn.setRequestMethod( "POST"); conn.setRequestProperty( "Content-Type", "application/soap+xml; charset=utf-8"); conn.setRequestProperty( "Content-Length", String. valueOf(data.length)); OutputStream outputStream = conn.getOutputStream(); outputStream.write(data); outputStream.flush(); outputStream.close(); if (conn.getResponseCode() == 200) { address =parseResponseXML(conn .getInputStream()); } } catch (Exception e) { } }; }; thread.start(); try { thread.join(); } catch (Exception e) {} if(address !=null){ return address ; } return null ; }
原文:http://www.cnblogs.com/LCX/p/4509628.html