开发学院手机开发Android 开发 如何成为Android开发高手 阅读

如何成为Android开发高手

 2010-08-31 00:43:00 来源:WEB开发网   
核心提示:String encode) throws Exception{254255//String params = "method=save&name="+ URLEncoder.encode("老毕", "UTF-8")+ "&age=28&"
String encode) throws Exception{

254

255//String params = "method=save&name="+ URLEncoder.encode("老毕", "UTF-8")+ "&age=28&";//需要发送的参数

256

257StringBuilder parambuilder = new StringBuilder("");

258

259if(params!=null && !params.isEmpty()){

260

261for(Map.Entry entry : params.entrySet()){

262

263parambuilder.append(entry.getKey()).append("=")

264

265.append(URLEncoder.encode(entry.getValue(), encode)).append("&");

266

267}

268

269parambuilder.deleteCharAt(parambuilder.length()-1);

270

271}

272

273byte[] data = parambuilder.toString().getBytes();

274

275URL url = new URL(path);

276

277HttpURLConnection conn = (HttpURLConnection)url.openConnection();

278

279conn.setDoOutput(true);//允许对外发送请求参数

280

281conn.setUseCaches(false);//不进行缓存

282

283conn.setConnectTimeout(5 * 1000);

284

285conn.setRequestMethod("POST");

286

287//下面设置http请求头

288

289conn.setRequestProperty("Accept", "image/gif, image/jpeg, image/pjpeg, image/pjpeg, application/x-shockwave-flash, application/xaml+xml, application/vnd.ms-xpsdocument, application/x-ms-xbap, application/x-ms-application, application/vnd.ms-excel, application/vnd.ms-powerpoint, application/msword, */*");

290

291conn.setRequestProperty("Accept-Language", "zh-CN");

292

293conn.setRequestProperty("User-Agent", "Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 5.2; Trident/4.0; .NET CLR 1.1.4322; .NET CLR 2.0.50727; .NET CLR 3.0.04506.30; .NET CLR 3.0.4506.2152; .NET CLR 3.5.30729)");

上一页  4 5 6 7 8 9 10 11 12 13 14  下一页

Tags:如何 成为 Android

编辑录入:coldstar [复制链接] [打 印]
[]
  • 好
  • 好的评价 如果觉得好,就请您
      0%(0)
  • 差
  • 差的评价 如果觉得差,就请您
      0%(0)
赞助商链接