String httpMethod = ""; RestTemplate restTemplate = new RestTemplate(); String args = ""; MultiValueMap<String, Object> paramMap = new LinkedMultiValueMap<>(); paramMap.add("args", args); paramMap.add("sign", ""); File file=new File("D:\\5a658c98Nd0abcb82.jpg"); byte[] bytesArray = new byte[(int) file.length()]; FileInputStream fis = new FileInputStream(file); fis.read(bytesArray); //read file into bytes[] fis.close(); ByteArrayResource contentsAsResource = new ByteArrayResource(bytesArray) { @Override public String getFilename() { return "img"; } }; paramMap.add("img", contentsAsResource);
JSONObject json = restTemplate.postForObject(httpMethod, paramMap, JSONObject.class);
System.out.println("post json : " + json);
注意點json
1.返回處理ide
2.MultiValueMappost