在Retrofit中发送POST请求中的空体 [英] Send empty body in POST request in Retrofit

查看:269
本文介绍了在Retrofit中发送POST请求中的空体的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的api在发布帖子请求时需要一个空的json正文( {} )。如何在Retrofit和Jackson中设置它?

My api expects an empty json body ({ }) when making post requests. How do I set this up in Retrofit and Jackson?

我尝试传递 null ,并清空字符串,并且{}但无法使其正常工作。

I tried passing null, and empty string, and "{}" but could not get this to work.

@POST(my/url)
Call<MyResponse> createPostRequest(@Body Object empty);

如何设置空的JSON正文?

How can I set an empty JSON body?

推荐答案

试试这个。它现在适用于我。

try this . It worked for me now.

@POST(my/url)
Call<MyResponse> createPostRequest(@Body Hashmap );

使用此方法时传递新的HasMap 为paremater

while using this method pass new HasMap as paremater

apiservice.createPostRequest(new HashMap())

这篇关于在Retrofit中发送POST请求中的空体的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆