Android 2如何将/放在动态baseUrl的末尾?
我已经使用Parcelable从json响应中发送和检索了一个url字符串,就像这样 收到的字符串值Android 2如何将/放在动态baseUrl的末尾?,android,retrofit2,Android,Retrofit2,我已经使用Parcelable从json响应中发送和检索了一个url字符串,就像这样 收到的字符串值 String profile_url = student.getProfile(); 我想使用这个字符串值作为basUrl,使用这样的改型来发出另一个请求 Retrofit retrofit = new Retrofit.Builder() .baseUrl(profile_url) .addConverterFa
String profile_url = student.getProfile();
我想使用这个字符串值作为basUrl,使用这样的改型来发出另一个请求
Retrofit retrofit = new Retrofit.Builder()
.baseUrl(profile_url)
.addConverterFactory(GsonConverterFactory.create())
.build();
但是得到以下错误
java.lang.RuntimeException: An error occured while executing doInBackground()
......
Caused by: java.lang.IllegalArgumentException: baseUrl must end in /:
如何将/放在baseUrl的末尾?
直截了当地说
Retrofit retrofit = new Retrofit.Builder()
.baseUrl(profile_url/)
.addConverterFactory(GsonConverterFactory.create())
.build();
不起作用,表示预期
任何帮助。谢谢
调试配置文件urlProfile\u url=http://services.hanselandstudent.com/student.svc/1.1/162137/category/1120/json?banner=0&atid=468f8dc2-9a38-487e-92ae-a194e81809d9
字符串变量的末尾必须有“/”
String profile_url = student.getProfile() + "/";
Retrofit retrofit = new Retrofit.Builder()
.baseUrl(profile_url)
.addConverterFactory(GsonConverterFactory.create())
.build();
字符串变量的末尾必须有“/”
String profile_url = student.getProfile() + "/";
Retrofit retrofit = new Retrofit.Builder()
.baseUrl(profile_url)
.addConverterFactory(GsonConverterFactory.create())
.build();
因为您有一个完整的url要调用,所以您需要在第2部分中使用@url注释 用类似的东西定义您的接口
public interface YourApiService {
@GET
Call<Profile> getProfile(@Url String url);
class Factory {
public static YourApiService createService() {
Retrofit retrofit = new Retrofit.Builder()
.addCallAdapterFactory(RxJavaCallAdapterFactory.create())
.baseUrl("http://www.what.com/")
.build();
return retrofit.create(YourApiService.class);
}
}
}
因为您有一个完整的url要调用,所以您需要在第2部分中使用@url注释 用类似的东西定义您的接口
public interface YourApiService {
@GET
Call<Profile> getProfile(@Url String url);
class Factory {
public static YourApiService createService() {
Retrofit retrofit = new Retrofit.Builder()
.addCallAdapterFactory(RxJavaCallAdapterFactory.create())
.baseUrl("http://www.what.com/")
.build();
return retrofit.create(YourApiService.class);
}
}
}
使用
端点
并制作自定义端点界面
@MD,对不起,我是新手,请给我更多指导。感谢您调试并发布您的配置文件\u url到底是什么?@Xiaoyowrm添加了调试配置文件url。这是绝对的url@Geob您是否可以在Chrome中安装高级Rest客户端扩展,并将您的URL复制粘贴到GET/POST/PUT/DELETE路径,以尝试查看是否可以得到响应。通常这就是我如何创建URL:Refundation Refundation=new Refundation.Builder().baseUrl(“http://yourServerip:port/”).addConverterFactory(GsonConverterFactory.create()).build();这就是接口的样子:@GET(“something”)调用getSomething();整个链接将是http://yourServerip:port/somethingUseEndpoint
和makecustomendpointinterface
@MD,对不起,我是新手,请给我更多指导。感谢您调试并发布您的配置文件\u url到底是什么?@Xiaoyowrm添加了调试配置文件url。这是绝对的url@Geob您是否可以在Chrome中安装高级Rest客户端扩展,并将您的URL复制粘贴到GET/POST/PUT/DELETE路径,以尝试查看是否可以得到响应。通常这就是我如何创建URL:Refundation Refundation=new Refundation.Builder().baseUrl(“http://yourServerip:port/”).addConverterFactory(GsonConverterFactory.create()).build();这就是接口的样子:@GET(“something”)调用getSomething();整个链接将是http://yourServerip:port/something。我也尝试过,同样的错误。原因:java.lang.IllegalArgumentException:baseUrl必须以/:结尾,您也尝试过,同样的错误。原因:java.lang.IllegalArgumentException:baseUrl必须以/: