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 寻一个支付宝扫码远程授权登录的软件助手app
  • ¥15 解riccati方程组
  • ¥15 display:none;样式在嵌套结构中的已设置了display样式的元素上不起作用?
  • ¥30 用arduino开发esp32控制ps2手柄一直报错
  • ¥15 使用rabbitMQ 消息队列作为url源进行多线程爬取时,总有几个url没有处理的问题。
  • ¥15 求chat4.0解答一道线性规划题,用lingo编程运行,第一问要求写出数学模型和lingo语言编程模型,第二问第三问解答就行,我的ddl要到了谁来求了
  • ¥15 Ubuntu在安装序列比对软件STAR时出现报错如何解决
  • ¥50 树莓派安卓APK系统签名
  • ¥65 汇编语言除法溢出问题
  • ¥15 Visual Studio问题