gpt4 book ai didi

android - 如何为 retrofit POST 调用设置动态端点?

转载 作者:塔克拉玛干 更新时间:2023-11-03 00:26:48 25 4
gpt4 key购买 nike

我从一个服务器接收到(Step 1)一个soapString,我想转发(Step 2)这个String到另一个服务器。

public interface StepTwoRestAdapter {
@Headers({"Content-Type:text/xml"})
@POST("/services/step2/forwardSoap")
Observable<String> order(@Body SoapString soapString);
}

在上面的这种情况下,afgter my.server.com 即“/webservices/step2/forwardSoap”始终保持不变。我怎样才能使这部分变量?

这里的技巧是,第二个服务器(用于步骤 2)在第一个响应的响应中指定。

编辑:现在,我使用@Tabish Hussain 的提议

public interface StepTwoRestAdapter {
@Headers({"Content-Type:text/xml"})
@POST("/{urlPath}")
Observable<String> order(@Body SoapString soapString, @Path("urlPath") String urlPath);

然后我调用

 restAdapter.create(StepTwoRestAdapter.class).order(new TypedString(soapString), uriPath)

而我的 uriPath 是“services/step2/forwardSoap”

但是改造然后调用: https://my.server.com/services%2Fstep2%2FforwardSoap

如您所见,“/”已被“%2F”替换

最佳答案

这样做

public interface StepTwoRestAdapter {
@Headers({"Content-Type:text/xml"})
@POST("/services/{soapString}/forwardSoap")
Observable<String> order(@Path("soapString") SoapString soapString);
}

关于android - 如何为 retrofit POST 调用设置动态端点?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41123995/

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