android的GET请求失败,一直无法发送
来源:互联网 发布:国泰安金融数据库 编辑:程序博客网 时间:2024/05/21 06:20
今天做安卓的时候,需要连接服务器,因为数据传的比较少 ,所以不想用post请求,用的get请求,但是一直无法成功,不得其原因,后来才知道get请求的URL中不能包含空格,
下面是post请求的代码,无注解,要详细看的,请看我以前的文章,网络请求必须开辟新的线程
private void sendRequest(final String sign){ new Thread(new Runnable() { @Override public void run() { String url="http://"+ MyIp.ip+":8080/CarSafe/InsertBlogServlet"; HttpURLConnection connection=null; try{ URL posturl=new URL(url); connection=(HttpURLConnection)posturl.openConnection(); connection.setDoOutput(true); connection.setDoInput(true); connection.setRequestMethod("POST"); connection.setUseCaches(false); connection.setInstanceFollowRedirects(true); connection.connect(); DataOutputStream out=new DataOutputStream(connection.getOutputStream()); String content="car_id="+ URLEncoder.encode(String.format("%d",Person.car_id),"utf-8")+ "&username="+URLEncoder.encode(Person.usename,"utf-8")+"&mysign="+URLEncoder.encode(sign,"utf-8"); out.writeBytes(content); out.flush(); out.close(); BufferedReader reader=new BufferedReader(new InputStreamReader(connection.getInputStream())); String line; StringBuffer response=new StringBuffer(); while((line=reader.readLine())!=null){ response.append(line); } reader.close(); Message message=new Message(); message.what=SEND_SIGN; message.obj=response.toString(); handler.sendMessage(message); }catch (Exception e){ e.printStackTrace(); }finally { if(connection!=null){ connection.disconnect(); } } } }).start();}
0 0
- android的GET请求失败,一直无法发送
- android发送get请求
- 在Android发送Get请求
- android中发送get请求
- [Socket]利用Android下的HttpClient发送GET && POST请求
- Android入门:发送HTTP的GET和POST请求
- Android入门:发送HTTP的GET和POST请求
- Android入门:发送HTTP的GET和POST请求
- Android入门:发送HTTP的GET和POST请求
- Android入门:发送HTTP的GET和POST请求
- Android开发中发送Get请求的实例
- android内置的HttpClient发送get、post请求用法
- http get请求发送失败,返回304错误
- Android中get请求无法获取Location信息的问题
- Android开发中如何发送Get请求!
- Android 发送请求 HTTP GET/POST
- Android开发中如何发送Get请求
- Android关于GET和POST发送请求
- 递归的基本原理
- Mac下让terminal复用上次会话
- RegExp 用一点心学,就不会觉得复杂
- chrome浏览器的跨域设置——包括版本49前后两种设置
- [Unity]Unity性能优化实战之GC优化(1)
- android的GET请求失败,一直无法发送
- 已知参考日期和过了多少天,计算现在的日期
- 软件可靠性
- Oracle 10gR2的client是无法登陆Oracle 12.2数据库
- Unity3D中手动添加Button的各类触发器
- 不重复订单号生成的方法
- Cadence Allegro学习之板框创建与网表导入与器件布局
- python 建造者模式(实现,特点)
- 鸟哥的linux私房菜学习笔记《二十一》变量及环境变量详解