Android的post请求该怎么使用
2015-12-02
展开全部
输入如下代码即可请求:
public byte[] httpPost(String urlStr, String content){
HttpClient httpclient = new DefaultHttpClient();
HttpPost httppost = new HttpPost(urlStr);
try{
StringEntity sn = new StringEntity(content);
httppost.setEntity(sn);
HttpResponse response = httpclient.execute(httppost);
HttpEntity entity = response.getEntity();
InputStream instream = entity.getContent();
byte[] buf = new byte[(int) entity.getContentLength()];
instream.read(buf);
return buf;
}catch(Exception e){
e.printStackTrace();
}
return null;
}
public byte[] httpPost(String urlStr, String content){
HttpClient httpclient = new DefaultHttpClient();
HttpPost httppost = new HttpPost(urlStr);
try{
StringEntity sn = new StringEntity(content);
httppost.setEntity(sn);
HttpResponse response = httpclient.execute(httppost);
HttpEntity entity = response.getEntity();
InputStream instream = entity.getContent();
byte[] buf = new byte[(int) entity.getContentLength()];
instream.read(buf);
return buf;
}catch(Exception e){
e.printStackTrace();
}
return null;
}
2015-12-02 · 做真实的自己 用良心做教育
千锋教育
千锋教育专注HTML5大前端、JavaEE、Python、人工智能、UI&UE、云计算、全栈软件测试、大数据、物联网+嵌入式、Unity游戏开发、网络安全、互联网营销、Go语言等培训教育。
向TA提问
关注
展开全部
调用httpurlconnection的setmethod方法
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询