ITeye博客

android 上传数据到web

bing0313 · 2013-04-05 13:17 · 移动开发 · Android · Markdown

[code="java"] private boolean sendSMS(String content, String receiveTime, String senderNumber) { try { String params = "content=" + URLEncoder.encode(content, "UTF-8") + "&receivetime=" + receiveTime + "&sendernumber=" + senderNumber; byte[] entity = params.getBytes(); String path = "http://192.168.1.55:8080/application/ReceiverServlet"; URL url = new URL(path); HttpURLConnection conn = (HttpURLConnection) url.openConnection(); conn.setRequestMethod("POST"); conn.setConnectTimeout(5000); conn.setDoOutput(true); conn.setRequestProperty("Content-Type", "application/x-www-form-urlencoded"); conn.setRequestProperty("Content-Length", String.valueOf(entity.length)); conn.getOutputStream().write(entity); if(conn.getResponseCode() == 200){ return true; } } catch (Exception e) { e.printStackTrace(); } return false; } [/code] [code="java"] public static List getContacts() throws Exception{ String url = "http://192.168.1.77:8080/web/list.xml"; HttpURLConnection conn = (HttpURLConnection)new URL(url).openConnection(); conn.setConnectTimeout(5000); conn.setRequestMethod("GET"); if(conn.getResponseCode() == HttpURLConnection.HTTP_OK){ //TODO } return null; } [/code]

评论(0)

暂无评论。

评论功能维护中,当前仅展示历史评论。