日期:2014-05-20 浏览次数:20692 次
//这里面两个参数 //url 服务器端servlet的访问地址 //aOutputData 字节数组 内容为key1=value1&key2=value2&key3=value3的形式 ,然后getBytes(); HttpURLConnection http=url.openConnection(); http.setConnectTimeout(5000); http.setReadTimeout(5000); http.setDoOutput(true); http.setDoInput(true); http.setAllowUserInteraction(false); http.setUseCaches(false); http.setRequestMethod("POST"); http.setRequestProperty("Content-Type", "application/x-www-form-urlencoded"); http.setRequestProperty("Content-Length", String .valueOf(aOutputData.length)); http.setRequestProperty("Connection", "close"); http .setRequestProperty( "User-Agent", "*** client"); http.setRequestProperty("Accept", "text/xml"); http.connect(); OutputStream out = http.getOutputStream(); out.write(aOutputData); out.flush();