Android Retrofit:内容类型为 application/x-www-form-urlencoded [英] Android Retrofit: content type as application/x-www-form-urlencoded

查看:30
本文介绍了Android Retrofit:内容类型为 application/x-www-form-urlencoded的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Android 开发的新手.我正在尝试使用改造来发送发布请求.在我的改造日志中,我看到

Fairly new to android development. I am trying to use retrofit to send a post request. In my retrofit logs, I am seeing

Content-Type: text/plain; charset=utf-8

我发现请求只有在我使用内容类型时才有效:

I found that requests will only work if I use the content type:

application/x-www-form-urlencoded

我搜索了谷歌并没有找到明确设置内容类型的明确方法.有人知道怎么做吗?

I have searched the googles and have found no clear way to explicitly set the content type. Anyone know how to do it?

推荐答案

在你定义服务的类中,修改相关方法,遵循以下模式:

In the class where you define your service, modify the related method to follow the pattern below:

@FormUrlEncoded
@POST/GET/PUT/DELETE("/your_endpoint")
Object yourMethodName(@Field("your_field") String yourField,...);

这篇关于Android Retrofit:内容类型为 application/x-www-form-urlencoded的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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