---
title: "android 上传数据到web"
author: "bing0313"
date: "2013-04-05T13:17:13Z"
tags: ["Android"]
categories: ["移动开发"]
slug: "android-web"
draft: true
lastmod: "2013-04-14T21:05:22Z"
id: 1842215
url: "https://bing0313.iteye.com/blog/1842215"
---

\[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]