Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

V2 POST 请求异常 #35

Open
neil-pan-s opened this issue May 28, 2021 · 1 comment
Open

V2 POST 请求异常 #35

neil-pan-s opened this issue May 28, 2021 · 1 comment

Comments

@neil-pan-s
Copy link

请求:
$.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
Copy link
Author

neil-pan-s commented May 29, 2021

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

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

问题代码:

if (method === 'POST') config['form'] = params;

修正代码 :

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) ;
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant