@Slf4j
public class CommonTest {
@Test
public void test() throws Exception {
File file = new File("file");
String url = "http://xxx";
BufferedReader reader = null;
reader = new BufferedReader(new FileReader(file));
HttpHeaders headers = new HttpHeaders();
headers.setContentType(MediaType.APPLICATION_FORM_URLENCODED);
RestTemplate restTemplate = new RestTemplate();
String tempString = null;
while ((tempString = reader.readLine()) != null) {
String phone = tempString.split(" ")[0];
String content = tempString.split(" ")[1];
MultiValueMap<String, String> map = new LinkedMultiValueMap<String, String>();
map.add("phone","111");
map.add("content","1111");
HttpEntity<MultiValueMap<String, String>> request = new HttpEntity<MultiValueMap<String, String>>(map, headers);
restTemplate.postForObject(url,request,String.class);
}
}
}
restTemplate 提交表单
最新推荐文章于 2023-12-25 11:36:24 发布
本文介绍了一个Java示例程序,该程序通过RestTemplate向指定URL发送POST请求。请求使用表单编码的内容类型,并从本地文件中读取电话号码和内容进行批量发送。

1392

被折叠的 条评论
为什么被折叠?



