我正在尝试创建一个postHTTP请求,其中包含一些要设置的表单参数.我正在使用带有节点服务器的axios.我已经有一个构建url的java代码实现,如下所示:
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"));
Run Code Online (Sandbox Code Playgroud)
我想在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
}
Run Code Online (Sandbox Code Playgroud)
在邮政要求上设置这些形式参数的方法是否正确?
所以后端(不在我的控制之下)需要一个像这样的查询字符串:
http://example.com/?foo=5&foo=2&foo=11
Run Code Online (Sandbox Code Playgroud)
但是axios使用JS对象发送请求参数:
axios.get('http://example.com/', { foo: 5 });
Run Code Online (Sandbox Code Playgroud)
显然,这样的对象不能有多个具有相同键的字段.
如何使用相同的密钥发送包含多个字段的请求?
我需要通过axios发出请求,在其中我想将这种类型的数组作为数组传递[1,2,3,4]。我需要这些数据来从我的后端进行选择查询,我的问题是:我应该使用GETorPOST请求以及传递这个数组的正确方法是什么?