import java.io.OutputStream;import java.net.HttpURLConnection;import java.net.URL;import java.util.Properties;import android.util.Log;import com.xxx.may.api.ASendManager;public class HTTPSend extends ASendManager {@Overridepublic void sendData(Properties paratemerproperties) {String tag ="HTTPSend:sendData";int statsID = 101;String s = "TYPE=101,102,103,104,105,100&NAME=1,2,3,4,5,6&VALUE=clicknews,2009-06-11-22:33:11,320,nomessageforyou,1000,NullPointException&IMEI=10001&APPID=91";String url1 = (String) paratemerproperties.get("post_data_url");Log.e(tag, "send the data:"+url1+s);try {URL url = new URL(url1);HttpURLConnection connection = (HttpURLConnection) url.openConnection();connection.setDoOutput(true);connection.setRequestMethod("POST");connection.setReadTimeout(20000);connection.setConnectTimeout(20000);OutputStream out = connection.getOutputStream();out.write(s.getBytes());out.flush();out.close();Log.e(tag, "Response code :"+connection.getResponseCode());connection.disconnect();} catch (Exception e) {e.printStackTrace();}}}/*** <p>* Resend the data when you want to* </p>* * @param data*            data* @throws IOException*             {@link IOException}*/private void resend(String datas[], String url,String appid) throws IOException {String tag = "HTTPSend:resend";DefaultHttpClient dhc = new DefaultHttpClient();HttpPost hp = new HttpPost(url1);HttpResponse httpResponse = null;List<NameValuePair> list = new ArrayList<NameValuePair>();list.add(new BasicNameValuePair(ParameterConstanst.TIME_API_SEND, System.currentTimeMillis()+ ""));list.add(new BasicNameValuePair(ParameterConstanst.APPLICATION_ID, appid));list.add(new BasicNameValuePair(ParameterConstanst.OS, "android"));list.add(new BasicNameValuePair(ParameterConstanst.PLATFORM, "1.5"));list.add(new BasicNameValuePair(ParameterConstanst.MSISDN, "000000000"));list.add(new BasicNameValuePair(ParameterConstanst.PROTOCOL_VERSION, "1"));list.add(new BasicNameValuePair(ParameterConstanst.IMEI, CollectIMEI.getIMEI()));list.add(new BasicNameValuePair(ParameterConstanst.TIME_API_CALLED, datas[0]));list.add(new BasicNameValuePair(ParameterConstanst.STATS_ID, datas[1].trim()));list.add(new BasicNameValuePair(ParameterConstanst.STATS_VALUE, datas[2].trim()));try {hp.setEntity(new UrlEncodedFormEntity(list));hp.setHeader(new BasicHeader(ParameterConstanst.TIME_OUT, "20000"));httpResponse = dhc.execute(hp);LogAPI.i(tag, "send data result : "+ httpResponse.getStatusLine().getStatusCode());} catch (ClientProtocolException e1) {LogAPI.e(tag, "[ Exception:+"+e1.getMessage()+" ]");} catch (IOException e1) {LogAPI.e(tag, "[ Exception:+"+e1.getMessage()+" ]");throw e1;}finally{hp.abort();LogAPI.e(tag, "[ finally in send data... ]");}}

更多相关文章

  1. 代码中设置drawableleft
  2. android 3.0 隐藏 系统标题栏
  3. Android开发中activity切换动画的实现
  4. Android(安卓)学习 笔记_05. 文件下载
  5. Android中直播视频技术探究之—摄像头Camera视频源数据采集解析
  6. 技术博客汇总
  7. android 2.3 wifi (一)
  8. AndRoid Notification的清空和修改
  9. Android中的Chronometer

随机推荐

  1. 【工作总结】一键清理总结
  2. android 5种布局
  3. 最全最好用的Android Studio插件整理
  4. Android(安卓)SlidingMenu侧滑菜单使用介
  5. Android Studio使用中遇到的问题
  6. Android答题app
  7. Android移动热修复--Sophix
  8. Android 异常捕获最少必要知识
  9. Android train——基本组件LinearLayout
  10. android AIDL简单步骤