这是我想使用 Retrofit2 访问的 URL。 http://makecodeeasy.com:49166/api/Customers
@POST(":49166/api/Customers")
Observable<LoginResponse>
login( @Body LoginRequest loginRequest);
这是我的 RetroClient:
public static Retrofit callInstance() {
Gson gson = new GsonBuilder()
.setLenient()
.create();
HttpLoggingInterceptor interceptor = new HttpLoggingInterceptor();
interceptor.setLevel(HttpLoggingInterceptor.Level.BODY);
final OkHttpClient client = new OkHttpClient.Builder()
.addInterceptor(interceptor)
.retryOnConnectionFailure(true)
.readTimeout(30, TimeUnit.SECONDS)
.connectTimeout(30, TimeUnit.SECONDS).build();
String ROOT_URL = "http://makecodeeasy.com";
return new Retrofit.Builder()
.baseUrl(ROOT_URL)
.addCallAdapterFactory(RxJavaCallAdapterFactory.create())
.client(client)
.addConverterFactory(GsonConverterFactory.create(gson))
.build();
}
I am getting the 404 Not Found error.
最佳答案
实际上,您犯了错误,您需要在基本网址内添加端口号,您可以在 api 调用时添加相对网址,但在基本网址中您需要传递包含端口号的完整基本路径。
按如下方式更改您的基础
String ROOT_URL = "http://makecodeeasy.com:49166";
和相对路径一样
@POST("/api/Customers")
关于java - 如何点击包含冒号的 Retrofit URL (:)?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48515894/