我试图创建一个带有一些表单参数的postHTTP请求。我正在使用Node服务器上的axios。我已经有了一个构造url的java代码实现,如下所示:
JAVA CODE:
JAVA CODE:
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
}
设置这些表单参数在POST请求中的方式是否正确?
application/x-www-form-urlencoded
,只需简单地使用querystring.stringify
来发送你想要发送的JSON数据。 - ThomasReggiimport qs from 'qs';
将你的对象转换为字符串。 - Ahmed Wahba