java - 带有 json 数据的 Java 请求
问题描述
我想用 Java 发出 HTTP 请求,但我是 Java 新手,不知道怎么做。我看过一些教程,但我无法理解任何东西。我想发送 JSON 数据并接收 JSON 数据。在 Python 中,它看起来像这样:
response = json.load(urllib.request.urlopen(urllib.request.Request('http://localhost:8765', requestJson)))
任何帮助将非常感激。
解决方案
使用以下链接作为参考 https://www.baeldung.com/java-http-request
如果您使用外部库,您也可以使用 rest 模板。
ResponseEntity<> response = restTemplate.exchange(
UriComponentsBuilder.fromHttpUrl(baseurl + "jobs").toString(),
HttpMethod.POST,
new HttpEntity<>(body,headers),
<someClass>.class);
推荐阅读
- ios - 根据背景图片设置导航栏大小
- azure - 全局只读权限和表级 RBAC
- javascript - 如何检测用户已取消页面加载
- mysql - Mysql中没有任何重复的三个表的并集减去一个表
- node.js - node-mssql - 指定数据库时用户身份验证失败
- app-inventor - 如何在按住按钮时保持计数器添加
- python - 使 Tkinter 标签和框架透明 Linux
- elasticsearch - 如何在 AWS ElasticSearch Service 的触发警报中获取变量值?
- python - 分析 uwsgi+nginx 背后的生产烧瓶应用程序
- architecture - 跨多个微服务共享数据