【发布时间】:2018-07-23 05:20:13
【问题描述】:
我有本地 asp .net core 2 IIS 服务器。当我使用发布请求时,我得到了结果。
但是当我尝试使用 retrofit2 从 andorid 请求时,我收到错误 400。
我的 android 设备和服务器连接到同一个 wifi 网络
邮递员返回
我正在使用我的服务器 pc ip 而不是 localhost 进行改造,因为改造不支持本地主机
改造客户端
@POST("/Auth/authenticate")
Call<ApiResponse> createAccount(@Body Request user);
改装电话
request = new Request("01532383497", "123");
retrofit = RetrofitInstance.getInstance();
client = retrofit.create(APIClient.class);
client.createAccount(request).enqueue(new Callback<ApiResponse>() {
@Override
public void onResponse(Call<ApiResponse> call, Response<ApiResponse> response) {
String a=response.body().getType();
Log.d("d","d");
}
@Override
public void onFailure(Call<ApiResponse> call, Throwable t) {
Log.d("d","d");
}
});
请求对象
public class Request {
String Username;
String Password;
public Request(String Username, String Password) {
Username = Username;
Password = Password;
}
public String getUsername() {
return Username;
}
public void setUsername(String username) {
Username = username;
}
public String getPassword() {
return Password;
}
public void setPassword(String password) {
Password = password;
}
}
改造实例
public class RetrofitInstance {
public static Retrofit retrofit = null;
public static final String END_POINT = "http://192.168.0.104:50111/api/";
public static Retrofit getInstance(){
if (retrofit == null){
retrofit = new Retrofit.Builder().baseUrl(END_POINT)
.addConverterFactory(GsonConverterFactory.create())
.build();
}
return retrofit;
}
}
【问题讨论】:
-
从 Auth @POST("/Auth/authenticate") 中删除 /
-
@Pavya 仍然无法正常工作
-
在邮递员中,您还添加了标题检查
-
@Pavya 这是邮递员默认标题我没有添加任何内容
-
你在你的服务器上尝试使用邮递员??
标签: android iis retrofit2 asp.net-core-2.0