原生的http请求
2016-02-18 17:29
483 查看
GET请求
String serverURL = "http://127.0.0.1/xxx/xx.jsp?username=abc;HttpGet httpRequest = new HttpGet(serverURL);// 建立http get联机HttpResponse httpResponse = new DefaultHttpClient().execute(httpRequest);// 发出http请求if (httpResponse.getStatusLine().getStatusCode() == 200)String result = EntityUtils.toString(httpResponse.getEntity());// 获取相应的字符串
POST请求
String uriAPI = "http://127.0.0.1/xxx/xx.jsp"; //声明网址字符串HttpPost httpRequest = new HttpPost(uriAPI); //建立HTTP POST联机List <NameValuePair> params = new ArrayList <NameValuePair>(); //Post运作传送变量必须用NameValuePair[]数组储存params.add(new BasicNameValuePair("str", "I am Post String"));httpRequest.setEntity(new UrlEncodedFormEntity(params, HTTP.UTF_8)); //发出http请求HttpResponse httpResponse = new DefaultHttpClient().execute(httpRequest); //取得http响应if(httpResponse.getStatusLine().getStatusCode() == 200)String strResult = EntityUtils.toString(httpResponse.getEntity()); //获取字符串
相关文章推荐
- Java IO:网络IO模型
- 脉络清晰的BP神经网络讲解,赞
- iOS开发之网络编程--3、NSURLSessionDataTask实现文件下载(离线断点续传下载)
- 通信协议:HTTP
- Struggling trying to get cookie out of response with HttpClient in .net 4.5
- 教你写Http框架(一)
- Error:Connection timed out: connect. If you are behind an HTTP proxy, please configure the proxy set
- IOS-网络(网页开发-UIWebView,HTML,CSS,JavaScript,OC和JS代码互调)
- USACO 4.2.1 网络流 最高标号预流推进(HLPP)
- PeopleRank从社交网络中发现个体价值
- 【网络流24题】搭配飞行员/飞行员配对方案
- HttpServletResponse
- socket http tcp 等
- iOS9 Xcode7 https解决方法
- 博客新地址 http://blog.devtao.com
- Socket Http
- TCP/IP协议详解学习笔记-- 链路层(包含CentOS6.5下抓包工具tcpdump的使用)
- [神经网络]1.4-Using neural nets to recognize handwritten digits-A simple network to classify ...(翻译)
- VMWare 网络连接模式(bridged、NAT、host-only)详解
- IP、TCP、UDP 协议格式,TCP状态机