down00112 2014-02-18 09:53
浏览 318
已采纳

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.

  • 写回答

2条回答 默认 最新

  • douwa6220 2014-02-18 14:01
    关注

    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.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 乌班图ip地址配置及远程SSH
  • ¥15 怎么让点阵屏显示静态爱心,用keiluVision5写出让点阵屏显示静态爱心的代码,越快越好
  • ¥15 PSPICE制作一个加法器
  • ¥15 javaweb项目无法正常跳转
  • ¥15 VMBox虚拟机无法访问
  • ¥15 skd显示找不到头文件
  • ¥15 机器视觉中图片中长度与真实长度的关系
  • ¥15 fastreport table 怎么只让每页的最下面和最顶部有横线
  • ¥15 java 的protected权限 ,问题在注释里
  • ¥15 这个是哪里有问题啊?