问题陈述
我是Spring / Rest应用程序的新手,我在中有数据Object
。
现在,我需要将此数据传递给API。
以下是附加在单个记录中的样本curl-
curl --request POST \
--url http://eventapi-dev.wynk.in/tv/events/v1/event \
--header 'cache-control: no-cache' \
--header 'content-type: application/json' \
--header 'postman-token: 67f73c14-791f-62fe-2b5a-179ba04f67ba' \
--data '{"name":"hotel california", "createdAt":1505727060471, "steamUrl":"https://www.youtube.com/watch?v=lHje9w7Ev4U"}'
我在终端击中卷曲网址后,得到的回应是好的
任何人都可以指导我如何用Java编写代码。
您可以使用okhttp(https://github.com/square/okhttp)调用此api。例:
OkHttpClient client = new OkHttpClient();
MediaType mediaType = MediaType.parse("application/json");
RequestBody body = RequestBody.create(mediaType, "{\n\t\"name\":\"hotel california\", \n\t\"createdAt\":1505727060471, \n\t\"steamUrl\":\"https://www.youtube.com/watch?v=lHje9w7Ev4U\"\n}");
Request request = new Request.Builder()
.url("http://eventapi-dev.wynk.in/tv/events/v1/event")
.post(body)
.addHeader("content-type", "application/json")
.addHeader("cache-control", "no-cache")
.addHeader("postman-token", "08af0720-79cc-ff3d-2a7d-f208202e5ec0")
.build();
Response response = client.newCall(request).execute();
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句