简体   繁体   English

在从Android调用Post请求时,Retrofit提供空响应

[英]Retrofit gives null response while calling Post request from android

Current response 当前反应

Response{protocol=http/1.0, code=404, message=Not Found, 
    url=http://testapp*****/api/dev/myapp**/subscription%2F2be110}

But url which i'm passing is 但是我传递的网址是

url=http://testapp*****/api/dev/myapp**/subscription/2be110

"subscription/2be110" which is passing as string to api service which receives at following function 作为字符串传递到在以下函数接收的api服务的“ subscription / 2be110”

@Headers("Content-Type: application/json;charset=UTF-8","Accept: application/json")
    @POST("{urlEndString}")
    fun getResponse(
        @Path ("urlEndString") urlEndString : String, @Body `object`: JsonObject
    ):Call<JsonObject>

How back slash changed to "%2F" format ? 反斜杠如何更改为“%2F”格式? Any solution to resolve this issue? 有解决此问题的解决方案吗?

Nb: using retrofit2 Nb:使用Retrofit2

@Path parameters are URLEncoded. @Path参数是URLEncoded。 Therefore slash will be URLEncoded as well. 因此,斜杠也将被URLEncoded。 You can use 2 path parameters like 您可以使用2个路径参数,例如

@POST("{urlEndString1}/{urlEndString2}")
fun getResponse(
        @Path ("urlEndString1") urlEndString1 : String, @Path ("urlEndString2") urlEndString2 : String, @Body `object`: JsonObject):Call<JsonObject>

And pass 2 parts of your URL ending split by slash. 并传递URL的2部分,以斜杠结尾。

As alternative, you can use @Path(value="urlEndString", encoded=true) to show that the parameter is already encoded, and Retrofit does not need to encode it. 或者,您可以使用@Path(value="urlEndString", encoded=true)表示该参数已被编码,而Retrofit不需要对其进行编码。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM