所用到的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 个月前
Logo

旨在为数千万中国开发者提供一个无缝且高效的云端环境,以支持学习、使用和贡献开源项目。

更多推荐