HttpURLConnection post json
来源:互联网 发布:拳击 泰拳 知乎 编辑:程序博客网 时间:2024/06/07 02:44
public Object createCouponShop(){
String access_token = getAccess_token();
String userListUrl="https://api.weixin.qq.com/card/landingpage/create?access_token="+access_token;
String message;
try {
URL url = new URL(userListUrl);
HttpURLConnection http = (HttpURLConnection)url.openConnection();
http.setRequestMethod("POST");
http.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
http.setDoOutput(true);
http.setDoInput(true);
System.setProperty("sun.net.client.defaultConnectTimeout", "30000");
System.setProperty("sun.net.client.defaultReadTimeout", "30000");
http.connect();
DataOutputStream out = new DataOutputStream(
http.getOutputStream());
String json="{\"banner\":\"http://pic.58pic.com/01/18/39/61bOOOPICdf.jpg\",\"page_title\":\"one year celebration coupon\",\"can_share\":false,\"scene\":\"SCENE_H5\",\"card_list\":[{\"card_id\":\"po7-6jl4t2OlINSjMMYvhBLKR8j0\",\"thumb_url\":\"http://pic.58pic.com/01/18/39/61bOOOPICdf.jpg\"}]}";
out.writeBytes(json);
out.flush();
out.close();
InputStream is = http.getInputStream();
int size = is.available();
byte jsonBytes[] = new byte[size];
is.read(jsonBytes);
message = new String(jsonBytes, "UTF-8");
return "CouponTest response:" + message;
} catch (Exception e) {
e.printStackTrace();
message = e.toString();
}
return message;
}
String access_token = getAccess_token();
String userListUrl="https://api.weixin.qq.com/card/landingpage/create?access_token="+access_token;
String message;
try {
URL url = new URL(userListUrl);
HttpURLConnection http = (HttpURLConnection)url.openConnection();
http.setRequestMethod("POST");
http.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
http.setDoOutput(true);
http.setDoInput(true);
System.setProperty("sun.net.client.defaultConnectTimeout", "30000");
System.setProperty("sun.net.client.defaultReadTimeout", "30000");
http.connect();
DataOutputStream out = new DataOutputStream(
http.getOutputStream());
String json="{\"banner\":\"http://pic.58pic.com/01/18/39/61bOOOPICdf.jpg\",\"page_title\":\"one year celebration coupon\",\"can_share\":false,\"scene\":\"SCENE_H5\",\"card_list\":[{\"card_id\":\"po7-6jl4t2OlINSjMMYvhBLKR8j0\",\"thumb_url\":\"http://pic.58pic.com/01/18/39/61bOOOPICdf.jpg\"}]}";
out.writeBytes(json);
out.flush();
out.close();
InputStream is = http.getInputStream();
int size = is.available();
byte jsonBytes[] = new byte[size];
is.read(jsonBytes);
message = new String(jsonBytes, "UTF-8");
return "CouponTest response:" + message;
} catch (Exception e) {
e.printStackTrace();
message = e.toString();
}
return message;
}
0 0
- HttpURLConnection post json传参
- HttpURLConnection post json
- HttpURLConnection post json
- HttpURLConnection post json 数据接口请求
- Android中如何使用HttpURLConnection实现GET POST JSON数据
- HttpClient和HttpUrlConnection实现post发送和接收json数据
- HttpURLconnection使用POST方式提交JSON数据给服务器
- HttpURLconnection使用POST方式提交JSON数据给服务器
- HttpURLConnection的post请求上传键值对和json数据
- Android HttpURLconnection使用POST请求参数是json
- HttpURLConnection 、HttpPost、Okhttp 等POST方式发送JSON数据
- Java 通过HttpURLConnection Post方式提交json,并从服务端返回json数据
- Java 通过HttpURLConnection Post方式提交json,并从服务端返回json数据
- Java 通过HttpURLConnection Post方式提交json,并从服务端返回json数据
- HttpURLConnection 的 POST 方法
- HttpURLConnection CookieManager Post提交
- HttpURLConnection post提交实例
- HttpURLConnection POST 上传文件
- 《你永远都无法叫醒一个装睡的人》经典语录
- 降低 lua gc 的开销
- IO流复制文件11种方法
- struts2配置default-properties
- chrome设置--disable-web-security解决跨域
- HttpURLConnection post json
- 生活中的物理、化学(四)
- python中的列表解析与函数参数*args **kwargs用法
- android ToolBar 的简单使用
- FFmpeg学习(二)
- Java中&&和&以及||和|的区别
- SensorManager 简介
- Cocos2d creator js 使用javascript制作扑克游戏
- 莫队算法小介绍——看似暴力的莫队算法