java - 如何点击包含冒号的 Retrofit URL (:)?

标签 java android url httpclient retrofit2

这是我想使用 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/

相关文章:

java - Action 监听器不适用于某些按钮

java - 从 ByteBuffer 中移除前 n 个字节

java - 将 URL 作为输入源的帮助

android - Adobe Air Mobile(iOS、Android)和来电

perl - 如何从 Perl 中的 URL 中仅提取方案、主机和端口?

ruby-on-rails-4 - Rails 重定向后如何强制使用某个 URL?

java错误: cannot find symbol EqualsUtil. areEqual

java - SQLite数据库创建openOrCreateDatabase,什么是应用程序数据库的正确路径

android - 如何使用 Phonegap Cli 构建 apk

Java MalformedURLException 被捕获