new Retrofit.Builder()
.baseUrl("http://myapirest/")
.addConverterFactory(GsonConverterFactory.create())
.build();
AlojamientoService servicio = retrofit.create(AlojamientoService.class);
EstablecimientoPublico publico= new EstablecimientoPublico("post", -79.097676, 4.987654, "ed...@gmail.com");
Call<EstablecimientoPublico> call = servicio.crearEstablecimiento(publico);
call.enqueue(new Callback<EstablecimientoPublico>() {
@Override
public void onResponse(Response<EstablecimientoPublico> response, Retrofit retrofit) {
Log.e("body", String.valueOf(response.body()));
Log.e("message", String.valueOf(response.message()));
Log.e("code", String.valueOf(response.code()));
}
@Override
public void onFailure(Throwable t) {
Log.e("error", t.getMessage());
}
})public interface AlojamientoService {
@GET("/categorias/1/")
Call<Alojamiento> getAlojamiento();
@Headers("Content-Type: application/json")
@POST("publicos/")
Call<EstablecimientoPublico> crearEstablecimiento(@Body EstablecimientoPublico publico);
}HttpLoggingInterceptor logging = new HttpLoggingInterceptor();
// set your desired log level
logging.setLevel(HttpLoggingInterceptor.Level.HEADERS);
OkHttpClient httpClient = new OkHttpClient();
// add your other interceptors …
// add logging as last interceptor
httpClient.interceptors().add(logging);// Ahora agrega el método .client y como parámetro el objeto httpClientRetrofit retrofit = new Retrofit.Builder()
.baseUrl("http://myapirest")
.addConverterFactory(GsonConverterFactory.create())
.client(httpClient)
.build();
Gracias a todos por su ayuda lo logre solucionar :)
HttpLoggingInterceptor logging = new HttpLoggingInterceptor();
logging.setLevel(HttpLoggingInterceptor.Level.BODY); // NOTA CAMBIE HEADERS POR BODY PORQUE NO ME MOSTRABA EL ERROR
OkHttpClient httpClient = new OkHttpClient();
httpClient.interceptors().add(logging);D/OkHttp: {"email":"ed...@gmail.com","latitud":-79.097676,"longitud":4.987654,"nombre":"android"}
D/OkHttp: --> END POST (87-byte body)
D/OkHttp: <-- HTTP/1.1 400 BAD REQUEST (612ms)
D/OkHttp: Date: Wed, 18 Nov 2015 23:25:56 GMT
D/OkHttp: Server: Apache/2.4.7 (Ubuntu)
D/OkHttp: Allow: GET, POST, HEAD, OPTIONS
D/OkHttp: X-Frame-Options: SAMEORIGIN
D/OkHttp: Vary: Accept,Cookie
D/OkHttp: Connection: close
D/OkHttp: Transfer-Encoding: chunked
D/OkHttp: Content-Type: application/json
D/OkHttp: OkHttp-Selected-Protocol: http/1.1
D/OkHttp: OkHttp-Sent-Millis: 1447890371797
D/OkHttp: OkHttp-Received-Millis: 1447890372028
D/OkHttp: {"correo":["This field is required."]}
D/OkHttp: <-- END HTTP (38-byte body)Sin ánimo de ofender ni crear polémicas, ya que te van ayudado y es posible que alguien más llegue aquí con el mismo problema, no estaría de más que dijeras cuál era el problema.
Un saludo!
--
Para participar es necesario que leas detenidamente las normas del grupo: http://goo.gl/8h8ez2
---
Has recibido este mensaje porque estás suscrito al grupo "desarrolladores-android" de Grupos de Google.
Para anular la suscripción a este grupo y dejar de recibir sus mensajes, envía un correo electrónico a desarrolladores-a...@googlegroups.com.
Para publicar en este grupo, envía un correo electrónico a desarrollad...@googlegroups.com.
Visita este grupo en http://groups.google.com/group/desarrolladores-android.
Para ver esta conversación en el sitio web, visita https://groups.google.com/d/msgid/desarrolladores-android/776c3aaf-7c09-4ccf-b76b-605bbf080e34%40googlegroups.com.
Para acceder a más opciones, visita https://groups.google.com/d/optout.