1

i have problems with my Webservice i created in php with the Laravel Framework.

I have the following URL to call:

http://localhost:100/cust/server.php/InitialSync/{"IdCard": "lxpIu1bD4UX4W2h5EM+i6VEQUZk+i\/SJF1DU6179HBejWkOBENSflnTSN\/8N14OGTqh6fH\/6kNrjJCilCMIrVtrlUAyQ5y8zZXVy5K3XwMOGmlHghAe80Q=="}

So you see that i send a Json Object with an crypted IdCard to the Server. My route looks like that:

Route::get('InitialSync/{idCard}, 'SyncController@InitialSync'};

So Problem is that this won´t work. I think the Problems are the / in the JsonObject.

Does anyone of you know how i can solve this problem.

The Result from Laravel is:

Symfony \ Component \ HttpKernel \ Exception \ NotFoundHttpException

I think he tries to find the Route but becouse of the / in the Json Object i get this error.

3
  • What kind of error is returned ? Your URL is strange. Why are you using port 100 ? What is cust path ? What is server.php file ? Commented Feb 18, 2014 at 10:03
  • possible duplicate of Need to allow encoded slashes on Apache Commented Feb 18, 2014 at 10:09
  • so, you think it´s a problem with apache? Commented Feb 18, 2014 at 11:54

2 Answers 2

4

Unfortunately Laravel can't undestand your browser will have trouble to process a JSON sent via GET, even if you encode and stringify it via Javascript:

encodeURIComponent(
  JSON.stringify(
    {"IdCard": "lxpIu1bD4UX4W2h5EM+i6VEQUZk+i\/SJF1DU6179HBejWkOBENSflnTSN\/8N14OGTqh6fH\/6kNrjJCilCMIrVtrlUAyQ5y8zZXVy5K3XwMOGmlHghAe80Q=="}
  )
)

Wich generates this string:

"%7B%22IdCard%22%3A%22lxpIu1bD4UX4W2h5EM%2Bi6VEQUZk%2Bi%2FSJF1DU6179HBejWkOBENSflnTSN%2F8N14OGTqh6fH%2F6kNrjJCilCMIrVtrlUAyQ5y8zZXVy5K3XwMOGmlHghAe80Q%3D%3D%22%7D"

Laravel will still have matters to recognize a route in that URL. This will not work.

The source of the problem is the escaped characters \/ present in the string. So you have some options:

1) Send it via POST

2) Base64 encode the IdCard and decode is back in Laravel.

3) Replace those characters by something else and revert it in Laravel.

4) Fill a bug in Laravel's Github repo and wait for them to fix it.

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

4 Comments

okay, i tried your solution now and i have the same problem i get error 404. My Problem is that i send a crypted string (AES) and my Laravel Route has to accept that.
My solution? I gave no solution, I gave you 3 options and none of those is a solution. After the code I shown I said Laravel will still have matters to recognize a route in that URL., which means that not even this will make it work.
okay... so that means, i have no change to handle this with a Get Request. So the only Solution is to make a Post and not a Get. Do you agree with this?
Yeah, if you can make a POST, it will succeed, but sometimes we just can't. Just edited to add this to my answer.
0

You could do something like this:

1) on your router:

Route::get('/readjson/{json}', 'MyController@readJson');

2) on your controller:

class MyController extends BaseController {

    public function readJson() {
        dd(request()->segments());
    }
}

That should print all the segments of the requested URI, including the param sent as a JSON string

3) Then just replace segments() with segment(n) to get the exact one. Should be number 2 in this case or 3 if you're using api routes (routes/api.php). From there you can use json_decode or anything else to decode the JSON string.

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.