JsonBird icon indicating copy to clipboard operation
JsonBird copied to clipboard

V2 POST 请求异常

Open neil-pan-s opened this issue 4 years ago • 1 comments

请求: $.ajax({ url: "https://bird.ioliu.cn/v2/?url=https://dataapi.joinquant.com/apis", type: 'POST', data: JSON.stringify({ "method": "get_concepts", "token": "5b6a9ba1b2f072b726667f2f", "code": "sw_l1", }), }

响应: error: invalid character '%' looking for beginning of value

neil-pan-s avatar May 28 '21 12:05 neil-pan-s

@xCss 此问题我fork了一个版本 已经解决了 方便的话 请核查下

问题原因: 所有POST数据 被统一设置到requst的参数form中,而对于JSON数据未区分判断设置到 request的参数body中

问题代码: https://github.com/xCss/JsonBird/blob/46cbb69b4b89cea17439a0925b0f3c12a1b22388/utils/utils.js#L74

修正代码 :

if (method === 'POST') {
    if (headers['content-type'].includes('application/x-www-form-urlencoded')) { 
        config['form'] = params; 
    } else if (headers['content-type'].includes('application/json')) { 
        config['body'] = JSON.stringify(params);
    } else {
        config['body'] = params;
    }
} else {
    config['url'] = config['url'] ? `${config['url']}?${qs.stringify(params)}` : (url?`${url}?${qs.stringify(params)}`:null) ;
}

neil-pan-s avatar May 29 '21 16:05 neil-pan-s