douzhang5121 2019-03-27 03:50
浏览 181

带有fetch api和laravel的查询字符串参数中的奇怪双重问号

Facing a very weird problem when posting query string params from browser(chrome) using fetch API and then parsing the params on server side with php-laravel, the parameter key is getting prepended with double question marks.

I am using aurelia fetch client if that matters.

let url = new URL('https://myapp.com/api/companies/');
    let param = {'id_owner': 34};
    url.search = new URLSearchParams(param);
    this.http.fetch(url, {
      mode: 'cors',
      method: 'get'
    })

on server side when I try to access id_owner nothing shows up. I added the following line in my controller(laravel) and the output

 public function index(Request $request)
    {
        return [$_SERVER['REQUEST_URI'], $_SERVER['QUERY_STRING'], $_POST, $_GET, $request->query('??id_owner'), $request->all()];

and surprisingly the output contains double question marks prepended to the key

[
"\/api\/companies\/?id_owner=34", // [$_SERVER['REQUEST_URI']
"??id_owner=34",      // $_SERVER['QUERY_STRING']
[],                   // $_POST
{"??id_owner":"34"},  // $_GET
"34",                 // $request->query('??id_owner') , a laravel feature
{"??id_owner":"34"}   // $request->all() , again a laravel feature
]

Ideally it should be simple and straightforward to use $_GET['id_owner'] to get the value but with added question marks it doesn't work. Where are they coming from ? Any idea what is going wrong?

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥20 fluent无法启动
    • ¥15 孟德尔随机化r语言运行问题
    • ¥15 pyinstaller编译的时候出现No module named 'imp'
    • ¥15 nirs_kit中打码怎么看(打码文件是csv格式)
    • ¥15 怎么把多于硬盘空间放到根目录下
    • ¥15 Matlab问题解答有两个问题
    • ¥15 LCD12864中文显示
    • ¥15 在使用CH341SER.EXE时不小心把所有驱动文件删除了怎么解决
    • ¥15 gsoap生成onvif框架
    • ¥15 有关sql server business intellige安装,包括SSDT、SSMS。