0

I have a problem that I havent been able to solve, I am connecting my Android app to a Laravel API, everything is working well, but when I try to send the JsonObject for the Post request it returns a 500 (I know 500 is an error of the server side, but Dingo likes to throw that code). The problem is, I just get this error when sending the JsonObject with the String variable names, but when I send the literal String, everything works fine. Ive already tried encoding to UTF-8. What could it be? I will leave my code below.

This way it works:

private void authorizeClient(String name, String secret, String ID){

    RequestQueue requestQueue = Volley.newRequestQueue(this);
    JSONObject jsonObject = new JSONObject();
    try{
        String secretFinal = URLEncoder.encode(secret, "UTF-8");
        jsonObject.put("grant_type", "client_credentials");
        jsonObject.put("name", name);
        jsonObject.put("client_secret", "c3melO2KvDQ:APA91bHYvSUJsSkB3dOKwk8zfgG0");
        jsonObject.put("client_id","287cdh27ldns7isvw7e3sd47ngau37t449123456");

This way it doesnt work:

private void authorizeClient(String name, String secret, String ID){

    RequestQueue requestQueue = Volley.newRequestQueue(this);
    JSONObject jsonObject = new JSONObject();
    try{
        String secretFinal = URLEncoder.encode(secret, "UTF-8");
        jsonObject.put("grant_type", "client_credentials");
        jsonObject.put("name", name);
        jsonObject.put("client_secret", secret);
        jsonObject.put("client_id",ID);
2
  • 1
    You are not using secretFinal in the second code snippet. Is that the reason why it does not work? Commented Jul 23, 2016 at 0:52
  • I tried it both with secret, secretFinal. Also I tries exchanging the String one by one, the name string works fine, but the secret and the id dont. I dont know if it has something to do with the simbols it has or the encoding. Commented Jul 23, 2016 at 15:09

1 Answer 1

0

Thanks, its all fixed. It was the lenght of the String that the database would not allow. I fixed it by making a substring.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.