Laravel PHP - 使用GET方法发送JSON对象

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.

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.

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.