Varun Jaiswal
Varun Jaiswal

Reputation: 67

HTTP/1.1 422 Unprocessable Entity Error when sending data to LoopBack from Java client

I am doing an HttpPost to send data to LoopBack and get the response. I am getting an error as below from LoopBack :

HTTP/1.1 422 Unprocessable Entity [X-Powered-By: Express, Vary: Origin, Accept-Encoding, Access-Control-Allow-Credentials: true, Content-Type: application/json; charset=utf-8, Content-Length: 1528, Date: Thu, 18 Dec 2014 18:13:45 GMT, Connection: keep-alive]

So, what I did in java is created a json from a java object , when I used this JSON in loopback api explorer, the data was inserted and gave me response 200, but doing from Java, I am getting this error. Does anyone have an idea about this. Java code is as below

 JSONObject json = new JSONObject(jsonString);
 StringEntity stringEntity = new StringEntity(json.toString());
 HttpClient client = new DefaultHttpClient();
 HttpPost post = new HttpPost(POST_CLAIM_URL);
 post.setEntity(stringEntity);
 HttpResponse httpResponse = null;
 httpResponse = client.execute(post);

I had make sure , I am not adding a duplicate entry.

Regards, Varun

Upvotes: 4

Views: 8556

Answers (1)

superkhau
superkhau

Reputation: 2781

For authentication, see this example https://github.com/strongloop/loopback-example-access-control.

As for the authentication token, you can set it in the query string of the request, like http://localhost:3000/api/your-model?access_token=TOKEN

Upvotes: 0

Related Questions