Axios Http客户端 – 如何构buildHttpurl与forms参数

我想创build一个postHTTP请求与一些表单参数将被设置。 我正在使用节点服务器的axios。 我已经有一个Java代码实现构造一个url,如下所示:

JAVA代码:

HttpPost post = new HttpPost(UriBuilder.fromUri (getProperty("authServerUrl")) .path(TOKEN_ACCESS_PATH).build(getProperty("realm"))); List<NameValuePair> formParams = new ArrayList<NameValuePair>(); formParams.add(new NameValuePair("username",getProperty ("username"))); formParams.add(new NameValuePair("password",getProperty ("password"))); formParams.add(new NameValuePair("client_id, "user-client")); 

我正在尝试在axios中做同样的事情。

AXIOS实施:

 axios.post(authServerUrl +token_access_path, { username: 'abcd', //gave the values directly for testing password: '1235!', client_id: 'user-client' }).then(function(response) { console.log(response); //no output rendered } 

在提交请求中设置这些表单参数的方法是否正确?

你必须做到以下几点:

 var querystring = require('querystring'); //... axios.post(authServerUrl + token_access_path, querystring.stringify({ username: 'abcd', //gave the values directly for testing password: '1235!', client_id: 'user-client' }), { headers: { "Content-Type": "application/x-www-form-urlencoded" } }).then(function(response) { console.log(response); });