在后台进行使用post调用接口并传递json参数
json
适用于现代 C++ 的 JSON。
项目地址:https://gitcode.com/gh_mirrors/js/json
免费下载资源
·
所用到的jar包
核心代码:
public class InterfaceTest{
public static void main(String[] args) {
try {
System.out.println(getMessage());
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
public static String getMessage()throws Exception{
JSONObject template = new JSONObject();
template.put("Name", "张三");
template.put("Pass","123456");
String urlString = "http://www.aiday.com.cn:10502/api/User/Login";
CloseableHttpClient httpClient = HttpClientBuilder.create().build();
HttpPost httpPost = new HttpPost(urlString);
httpPost.addHeader(HTTP.CONTENT_TYPE, "application/json");
StringEntity entity;
entity = new StringEntity(template.toString());
System.out.println(template.toString());
httpPost.setEntity(entity);
HttpResponse response;
response = httpClient.execute(httpPost);
/*InputStream inputStream = response.getEntity().getContent();
String name1 = name+".png"; //图片的名称
*/
//获取返回
HttpEntity entitys = response.getEntity();
BufferedReader in = new BufferedReader(new InputStreamReader(entitys.getContent(), "UTF-8"));
StringBuffer buffer = new StringBuffer();
String line = null;
while ((line = in.readLine()) != null) {
buffer.append(line);
}
return buffer.toString();
}
}
GitHub 加速计划 / js / json
41.72 K
6.61 K
下载
适用于现代 C++ 的 JSON。
最近提交(Master分支:1 个月前 )
960b763e
3 个月前
8c391e04
6 个月前
更多推荐
已为社区贡献1条内容
所有评论(0)