gpt4 book ai didi

java - 如何使用 android 注释和 resttemplate 在 POST 请求正文中发送 x-www-form-urlencoded

转载 作者:塔克拉玛干 更新时间:2023-11-02 21:16:36 31 4
gpt4 key购买 nike

我的界面如下所示:

@Rest(rootUrl = "https://myurl.com", converters = { GsonHttpMessageConverter.class })
public interface CommunicatonInterface
{
@Get("/tables/login")
public Login login(Param param);
public RestTemplate getRestTemplate();
}

问题是我应该将什么作为参数放入 body 中:

login=myName&password=myPassword&key=othereKey

没有转义、括号或配额。

我尝试传递一个字符串,但我得到:"login=myName&password=myPassword&key=otherKey" 但由于配号是错误的。

最佳答案

如果我没理解错的话,你想将表单中的 loginpassword 参数传递给你的方法。

为此,您应该确保执行以下步骤:

  1. 创建一个登录表单,其中包含以 loginpassword 作为名称的输入文本字段。
  2. 确保 form 有一个 POST 方法,你真的不想在 URL 中将用户的凭据作为获取参数,但如果你用例需要你做到这一点,你可以。
  3. 在您的 Interface 中,您应该使用 FormHttpMessageConverter 而不是使用 GsonHttpMessageConverter。此转换器接受并返回带有 application/x-www-form-urlencoded 的内容,这是表单提交的正确 content-type
  4. 您的Param 类应具有与输入文本字段同名的字段。在您的例子中,loginpassword。执行此操作后,表单中发布的请求参数将在 param 实例中可用。

希望这对您有所帮助。

关于java - 如何使用 android 注释和 resttemplate 在 POST 请求正文中发送 x-www-form-urlencoded,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19681493/

31 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com