Retrofit 在从 android 调用 Post 请求时给出空响应
Retrofit gives null response while calling Post request from android
当前回复
Response{protocol=http/1.0, code=404, message=Not Found,
url=http://testapp*****/api/dev/myapp**/subscription%2F2be110}
但是我传递的 url 是
url=http://testapp*****/api/dev/myapp**/subscription/2be110
"subscription/2be110" 作为字符串传递给 api 服务,该服务在以下函数接收
@Headers("Content-Type: application/json;charset=UTF-8","Accept: application/json")
@POST("{urlEndString}")
fun getResponse(
@Path ("urlEndString") urlEndString : String, @Body `object`: JsonObject
):Call<JsonObject>
如何将反斜杠更改为“%2F”格式?有解决此问题的方法吗?
Nb: 使用 retrofit2
@Path
参数已 URL 编码。因此斜线也会被 URL 编码。您可以使用 2 个路径参数,例如
@POST("{urlEndString1}/{urlEndString2}")
fun getResponse(
@Path ("urlEndString1") urlEndString1 : String, @Path ("urlEndString2") urlEndString2 : String, @Body `object`: JsonObject):Call<JsonObject>
并传递 URL 结尾的 2 部分,用斜杠分隔。
作为替代,你可以使用@Path(value="urlEndString", encoded=true)
表示参数已经编码,Retrofit不需要编码。
当前回复
Response{protocol=http/1.0, code=404, message=Not Found,
url=http://testapp*****/api/dev/myapp**/subscription%2F2be110}
但是我传递的 url 是
url=http://testapp*****/api/dev/myapp**/subscription/2be110
"subscription/2be110" 作为字符串传递给 api 服务,该服务在以下函数接收
@Headers("Content-Type: application/json;charset=UTF-8","Accept: application/json")
@POST("{urlEndString}")
fun getResponse(
@Path ("urlEndString") urlEndString : String, @Body `object`: JsonObject
):Call<JsonObject>
如何将反斜杠更改为“%2F”格式?有解决此问题的方法吗?
Nb: 使用 retrofit2
@Path
参数已 URL 编码。因此斜线也会被 URL 编码。您可以使用 2 个路径参数,例如
@POST("{urlEndString1}/{urlEndString2}")
fun getResponse(
@Path ("urlEndString1") urlEndString1 : String, @Path ("urlEndString2") urlEndString2 : String, @Body `object`: JsonObject):Call<JsonObject>
并传递 URL 结尾的 2 部分,用斜杠分隔。
作为替代,你可以使用@Path(value="urlEndString", encoded=true)
表示参数已经编码,Retrofit不需要编码。