2017-02-09 103 views
1

我想使用改装,但我得到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“)

+0

请显示代码改造2 –

+0

实际上是您的github项目兄弟大声笑,我试图使用我自己的服务,但我得到一个空对象对我的回应(服务器发送回应) –

+0

哈哈哈家伙我'创造者这个回购XD哈哈你使用模拟器? –

回答

0

更多钞票的解决方案

1:如果你的服务是local,记得使用

Genymotion

http://10.0.3.2/

默认AVD

http://10.0.2.2/

2:检查您的端点校正

usersFake 
login 

3:我在我的本地个案,我有nginx的和我有一个问题,使用模拟器

+0

我的服务不是本地的在互联网上发布,我的终端实际上​​是正确的我到达了我的WS,但我的回应为空翻新回调(服务器日志我看到整个过程与有效的回应):( –

+0

也许你的JSON responde不,它是正确的,请使用此页面进行验证http://www.jsonschema2pojo.org/ ---- http://jsonlint.com/ –

+0

是我实际使用的相同服务,我已经开发了一个应用程序类和服务,但现在我想把它移动到清洁架构,我曾用我的客户端与一个HTTP客户端打电话,然后用gson解析它我使用相同的,它不能是对象或JSON( json的帖子),为什么我不明白发生了什么事情:( –

0

我昨天遇到了同样的问题访问。试试这个:

在浏览器中检查您的工作网址。如果您的网址端点具有.php等任意扩展名,请将其添加到GET/POST注释参数中,并编写像@GET("userFake.php")这样的全名。

这对我有效。希望它也适用于你。

+0

感谢您编辑我的语法错误 - @ sud007 –

+0

你好,我的服务是一个Java服务,端点是好的我可以看到请求o n服务器端我可以在服务器端看到响应,但翻新获得空响应:( –

+0

首先使用Postman检查mobile/tvs生成的问题? –