HttpClient HttpPost请求
来源:互联网 发布:双击python文件闪退 编辑:程序博客网 时间:2024/04/29 21:41
import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;
import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.NameValuePair;
import org.apache.http.client.HttpClient;
import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.message.BasicNameValuePair;
import android.util.Log;
public class AndHttpPost {
public static String request(String data, String url) {
try {
// 数据实体
List<NameValuePair> list = new ArrayList<NameValuePair>();
list.add(new BasicNameValuePair("isucvip", data));
HttpEntity httpEntity = new UrlEncodedFormEntity(list, "UTF-8");
// 打开一个浏览器
HttpClient httpClient = new DefaultHttpClient();
// 输入地址
HttpPost httpPost = new HttpPost(url);
httpPost.setEntity(httpEntity);
// 客户端对象来发送请求
HttpResponse httpResponse = httpClient.execute(httpPost);
int code = httpResponse.getStatusLine().getStatusCode();
if (code == 200) {
HttpEntity entity = httpResponse.getEntity();
InputStream inputStream = entity.getContent();
BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream));
String result = "";
String line = "";
while (null != (line = reader.readLine())) {
result += line;
}
reader.close();
inputStream.close();
Log.e("AndHttpPost", "result = " + result + " jsonStr = " + data);
return result;
} else {
return null;
}
} catch (Exception e) {
e.printStackTrace();
return null;
}
}
}
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;
import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.NameValuePair;
import org.apache.http.client.HttpClient;
import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.message.BasicNameValuePair;
import android.util.Log;
public class AndHttpPost {
public static String request(String data, String url) {
try {
// 数据实体
List<NameValuePair> list = new ArrayList<NameValuePair>();
list.add(new BasicNameValuePair("isucvip", data));
HttpEntity httpEntity = new UrlEncodedFormEntity(list, "UTF-8");
// 打开一个浏览器
HttpClient httpClient = new DefaultHttpClient();
// 输入地址
HttpPost httpPost = new HttpPost(url);
httpPost.setEntity(httpEntity);
// 客户端对象来发送请求
HttpResponse httpResponse = httpClient.execute(httpPost);
int code = httpResponse.getStatusLine().getStatusCode();
if (code == 200) {
HttpEntity entity = httpResponse.getEntity();
InputStream inputStream = entity.getContent();
BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream));
String result = "";
String line = "";
while (null != (line = reader.readLine())) {
result += line;
}
reader.close();
inputStream.close();
Log.e("AndHttpPost", "result = " + result + " jsonStr = " + data);
return result;
} else {
return null;
}
} catch (Exception e) {
e.printStackTrace();
return null;
}
}
}
0 0
- HttpClient HttpPost请求
- Java HttpPost请求基于apache的httpclient
- Java的HttpClient、HttpGet和HttpPost请求
- httpClient httpPost
- java中用httpClient请求service,httpPost方法示例
- 利用HTTPClient模块中HttpGet和HttpPost 发送接口请求
- HttpClient 四种请求访问代码 HttpGet HttpPost HttpPut HttpDelete
- 关于HttpClient HttpGet和HttpPost 请求的运用
- HttpGet/HttpPost/HttpClient介绍
- HTTPClient模块的HttpGet和HttpPost(处理http请求响应)
- 使用HttpClient发送HttpPost请求包含上传本地图片和远程图片的传输实现
- Android HttpClient && HttpPost简单使用
- Android HttpClient && HttpPost简单使用
- HttpClient通过HttpPost传递参数
- Android HttpClient,httpPost基本使用方法
- HttpClient通过HttpPost传递参数
- HttpClient与httpComponents、HttpPost、HttpGet
- httpclient中PostMethod和HttpPost
- django Q和F查询
- 集合框架的一些理解
- DirectDraw 简单示例
- linux 限速工具 netem bridge
- Python命名规范
- HttpClient HttpPost请求
- Git下载子模块
- Swift基础语法: 24 - Swift的枚举语法, 匹配枚举值和 Switch 语句, 关联值, 原始值
- maven私服搭建
- Proguard随笔
- 使用CALayer的delegate绘制layer的内容导致程序崩溃
- 迁移学习 transfer learning
- C语言学习笔记(十五) -网络 TCP协议
- Navicat MySQL连接Linux下MySQL的问题解决方案