我想使用改装,但我得到404码和消息“未找到”改造2找不到404
响应{protocol=http/1.1, code=404, message=Not Found}
我可以在我的服务器日志,该请求是成功和看响应是与对象
我用GSON
到解析它{
"codigoRespuesta": "00",
"descRespuesta": "Success",
"token": "0bc6e8a352a002db5782ae729501fd05bd825cf165864a0ab32d1ab1529001ed2583df4a5ab257a30f97117ec0fec0b6df60adf288fd6b1579f31d2d636d9aa"
}
所以我使用与改型相同的对象,我使用异步操作请求使用
public class AuthenticationResponse extends Response {
private String token;
public AuthenticationResponse() {
}
public AuthenticationResponse(String codigoRespuesta, String descRespuesta) {
super(codigoRespuesta, descRespuesta);
}
public AuthenticationResponse(String codigoRespuesta, String descRespuesta, String token) {
super(codigoRespuesta, descRespuesta);
this.token = token;
}
public String getToken() {
return this.token;
}
public void setToken(String token) {
this.token = token;
}
public String toString() {
return "AuthenticationResponse{token=" + this.token + ", " + super.toString() + '}';
}
}
@XmlRootElement
public class Response {
private String codigoRespuesta;
private String descRespuesta;
public Response() {
}
public Response(String codigoRespuesta, String descRespuesta) {
this.codigoRespuesta = codigoRespuesta;
this.descRespuesta = descRespuesta;
}
@XmlElement
public String getCodigoRespuesta() {
return this.codigoRespuesta;
}
public void setCodigoRespuesta(String codigoRespuesta) {
this.codigoRespuesta = codigoRespuesta;
}
@XmlElement
public String getDescRespuesta() {
return this.descRespuesta;
}
public void setDescRespuesta(String descRespuesta) {
this.descRespuesta = descRespuesta;
}
public String toString() {
return "codigoRespuesta=" + this.codigoRespuesta + ", descRespuesta=" + this.descRespuesta;
}
}
该项目正是基于这样的例子 github project
我的更新接口
public interface servicesTutorial {
@GET("usersFake")
Call<List<ResponseService>> getUsersGet();
@POST("usersFake")
Call<List<ResponseService>> getUsersPost();
@POST("login")
Call<AuthenticationResponse> doLogin(@Body RequestLogin request);
}
我的MainActivity类别
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Gson gson = new GsonBuilder()
.setLenient()
.create();
final String url = "https://myurl.com/";
Retrofit retrofit = new Retrofit.Builder()
.baseUrl(url)
.addConverterFactory(GsonConverterFactory.create(gson))
.build();
servicesTutorial serviceTuto = retrofit.create(servicesTutorial.class);
Call<AuthenticationResponse> call2 = serviceTuto.doLogin(new RequestLogin("user","pwd"));
call2.enqueue(new Callback<AuthenticationResponse>() {
@Override
public void onResponse(Call<AuthenticationResponse> call, Response<AuthenticationResponse> response) {
Log.e("testing", "respuesta: "+response.message()+" *** "+response.code()+" *** "+response.isSuccessful() +
" *** " + response.raw().toString());
}
@Override
public void onFailure(Call<AuthenticationResponse> call, Throwable t) {
Log.e("testing",t.toString());
}
});
}
}
编辑: 我终于得到它,appareantly因为我的服务与Java和春天做我不得不头添加到我的请求(“接受:应用程序/ JSON“)
请显示代码改造2 –
实际上是您的github项目兄弟大声笑,我试图使用我自己的服务,但我得到一个空对象对我的回应(服务器发送回应) –
哈哈哈家伙我'创造者这个回购XD哈哈你使用模拟器? –