1

Hello I'm trying to send raw json through object to server without success with Retrofit library.Tried some recommendation from this question but not success How to POST raw whole JSON in the body of a Retrofit request? So my code is:

        Prod tag = new Prod();
        tag.setName(name);
        tag.email(email);

        String json = JsonUtilFactory.getJsonUtil().toJson(tag);
        TypedJsonString in = new TypedJsonString(json);

        service.checkProduct(in, new Callback<Object>()

  @PUT("/api/scans")
public void request(@Body TypedJsonString typedInput, Callback<Object>   callback);

 public class TypedJsonString extends TypedString {
    public TypedJsonString(String body) {
        super(body);
    }

    @Override public String mimeType() {
        return "application/json";
    }
}

So in every when I make request to server I got error like this

     D/Retrofit﹕ ---> HTTP PUT https://somehost.com/call
D/Retrofit﹕ Content-Type: application/json
D/Retrofit﹕ Content-Length: 125
D/Retrofit﹕ {"name":"prod_name","email":"my@email"}
 D/Retrofit﹕ ---> END HTTP (125-byte body)
I/Adreno-EGL﹕ <qeglDrvAPI_eglInitialize:379>: QUALCOMM Build: 01/14/15, ab0075f, Id3510ff6dc
 I/OpenGLRenderer﹕ Initialized EGL, version 1.4
28418-28855/co.otenti D/OpenGLRenderer﹕ Enabling debug mode 0
05-28 21:53:18.768      735-831/? I/ActivityManager﹕ Displayed co.otenti/.activity.MenuActivity: +9s186ms
 D/Retrofit﹕ <--- HTTP 404 https://somehost.com/call (933ms)
 D/Retrofit﹕ Server: nginx/1.6.2
 D/Retrofit﹕ Date: Thu, 28 May 2015 18:53:20 GMT
D/Retrofit﹕ Content-Type: text/html; charset=utf-8
 D/Retrofit﹕ Transfer-Encoding: chunked
D/Retrofit﹕ Connection: keep-alive
 D/Retrofit﹕ X-Powered-By: Express
 D/Retrofit﹕ X-Content-Type-Options: nosniff
 D/Retrofit﹕ Set-Cookie: connect.sid=s%3AJagAmIPjbhpZwojw6AatazyL.ZKrtIC31UyHVSyBuN98pvYTaW9I%2BpeNr5XnEDS8yWrw; Path=/; HttpOnly
D/Retrofit﹕ Vary: Accept-Encoding
 D/Retrofit﹕ OkHttp-Selected-Protocol: http/1.1
 D/Retrofit﹕ OkHttp-Sent-Millis: 1432839199295
 D/Retrofit﹕ OkHttp-Received-Millis: 1432839199483
 D/Retrofit﹕ Cannot PUT /api/scans 

Can some one explain ,e what I'm doing wrong?

Also previous code looked like this

  JSONObject obj = JsonFactory.toJson(prod,Prod.class)

        httpPost.setEntity(new StringEntity(obj.toString()));
        httpPost.setHeader("Accept", "application/json");
        httpPost.setHeader("Content-type", "application/json");
Community
  • 1
  • 1
Terry
  • 63
  • 3
  • 10

0 Answers0