java raw方式 的实现代码如下:
Url url = new Url("");
HttpURLConnection connection = (HttpURLConnection ) url.oepnConnection();
connection.setDoOutput(true);
connection.setDoInput(true);
connection.setUseCaches(false);
connection.setInstanceFollowRedirects(true);
connection.setRequestMethod("POST");
connection.setRequestProperty("Accept","application/json,charset=utf-8");
connection.connect();
OutputStreamWriter out = new OutputStreamWriter(connection.getOutputStream(),"UTF-8");
out.append(params);
out.flush();
out.close();
BufferedReader reader = new BufferedReader(new InputStreanReader(connect.getInputStream(),"UTF-8");
String str = "";
while((line = reader.readLine())!= null){
res += line;
}
reader.close();
java form-data方式 的实现代码如下:
LinkedMultiValueMap<String,Object> map= new LinkedMultiValueMap<String,Object>();
map.add("",new ArrayList);//放list对象
map.add("",new String("111"));//放string
RestTemplate template = new RestTemplate();
HttpHeaders headers = new HttpHeaders();
HttpEntity<LinkedMultiValueMap<String,Object>> request = HttpEntity<LinkedMultiValueMap<String,Object>>(map,headers);
ResponseEntity responseEntity = template.postEntity(url,request,String.class);
HttpStatus statusCode = responseEntity .getStatusCode();
String resultString = responseEntity.getBody();文章来源:https://www.toymoban.com/news/detail-404989.html
亲测,完全ok。文章来源地址https://www.toymoban.com/news/detail-404989.html
到了这里,关于JAVA实现postman form-data和raw方式请求数据的代码的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!