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 画两个图 python或R
  • ¥15 在线请求openmv与pixhawk 实现实时目标跟踪的具体通讯方法
  • ¥15 八路抢答器设计出现故障
  • ¥15 opencv 无法读取视频
  • ¥15 用matlab 实现通信仿真
  • ¥15 按键修改电子时钟,C51单片机
  • ¥60 Java中实现如何实现张量类,并用于图像处理(不运用其他科学计算库和图像处理库))
  • ¥20 5037端口被adb自己占了
  • ¥15 python:excel数据写入多个对应word文档
  • ¥60 全一数分解素因子和素数循环节位数