• 首页 首页 icon
  • 工具库 工具库 icon
    • IP查询 IP查询 icon
  • 内容库 内容库 icon
    • 快讯库 快讯库 icon
    • 精品库 精品库 icon
    • 问答库 问答库 icon
  • 更多 更多 icon
    • 服务条款 服务条款 icon

java.lang.IllegalArgumentException: baseUrl must end in /: http://xxx.xxx.com/cric

武飞扬头像
Android_小白
帮助1

Retrofit2 报错baseUrl must end in /

依赖

  1.  
    // Rxjava
  2.  
    implementation 'io.reactivex.rxjava2:rxandroid:2.0.1'
  3.  
    implementation 'io.reactivex.rxjava2:rxjava:2.0.5'
  4.  
    // retrofit 网络 请求
  5.  
    implementation 'com.squareup.retrofit2:retrofit:2.4.0'
  6.  
    // implementation 'com.jakewharton.retrofit:retrofit2-rxjava2-adapter:1.0.0'
  7.  
    implementation 'com.squareup.retrofit2:adapter-rxjava2:2.2.0'
  8.  
    implementation ('com.squareup.retrofit2:converter-gson:2.7.0'){
  9.  
    exclude group : 'com.谷歌.code.gson'
  10.  
    }

现象:

  1.  
    builder.baseUrl(http://xxx.xxx.com/cric);
  2.  
  3.  
    builder.baseUrl(http://xxx.xxx.com/cric/);
  4.  
  5.  
     
  6.  
    @POST("/index.php?m=&c=app&a=sendSMS")
  7.  
    Call<ResponseBody> sendSMS2(@Body RequestBody body);

请求时报错现象可能又两种

错误1. baseUrl must end in /: http://xxx.xxx.com/cric

错误2:打印日志显示 的请求路径:http://xxx.xxx.com/index.php?m=&c=app&a=sendSMS.重路径中看到少了 /cric 这个。

解答案决:

  1.  
    // 设置路径最后面带斜杠 “/”
  2.  
    builder.baseUrl(http://xxx.xxx.com/cric/);
  3.  
  4.  
    // 接口这里最前面不要带斜杠 “/”
  5.  
    @POST("index.php?m=&c=app&a=sendSMS")
  6.  
    Call<ResponseBody> sendSMS2(@Body RequestBody body);
 详细原因参考:Retrofit2 的baseUrl 真的必须以 /(斜线) 结尾吗? - 简书

这篇好文章是转载于:学新通技术网

  • 版权申明: 本站部分内容来自互联网,仅供学习及演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,请提供相关证据及您的身份证明,我们将在收到邮件后48小时内删除。
  • 本站站名: 学新通技术网
  • 本文地址: /boutique/detail/tanhgfkehb
系列文章
更多 icon
同类精品
更多 icon
继续加载