一、POST传值方法
public static String SendUlr(String requestUrl,String xml) { String responseStr=""; try { URL url = new URL(requestUrl); HttpURLConnection urlConnection = (HttpURLConnection)url.openConnection(); urlConnection.setDoOutput(true); urlConnection.setDoInput(true); urlConnection.setRequestMethod("POST"); urlConnection.setUseCaches(false); urlConnection.setInstanceFollowRedirects(true); urlConnection.setRequestProperty("Content-Type","application/x-www-form-urlencoded"); urlConnection.setRequestProperty("Charset", "UTF-8"); urlConnection.connect(); DataOutputStream out = new DataOutputStream(urlConnection.getOutputStream()); String params= xml; out.write(params.getBytes("UTF-8")); /* out.writeBytes(params);*/ out.flush(); out.close(); BufferedReader reader = new BufferedReader(new InputStreamReader(urlConnection.getInputStream(),"UTF-8")); String line; while ((line = reader.readLine()) != null){ responseStr+=line; } reader.close(); urlConnection.disconnect(); }catch (MalformedURLException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (ProtocolException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } return responseStr; }