Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/131.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ Moodle REST webservice:将数组作为POST参数发送时出现问题_C++_Qt_Rest_Moodle - Fatal编程技术网

C++ Moodle REST webservice:将数组作为POST参数发送时出现问题

C++ Moodle REST webservice:将数组作为POST参数发送时出现问题,c++,qt,rest,moodle,C++,Qt,Rest,Moodle,我将Moodle REST Web服务与Qt结合使用。登录有效,其他具有单个参数的功能也有效 现在我想使用函数“core\u user\u update\u users”,它将数组作为参数 官方文件说: 一般结构: list of ( object { id int //ID of the user username string Optional //Username policy is defined in Moodle security config. ... //more opt

我将Moodle REST Web服务与Qt结合使用。登录有效,其他具有单个参数的功能也有效

现在我想使用函数“core\u user\u update\u users”,它将数组作为参数

官方文件说:

一般结构:

list of ( 
object {
id int   //ID of the user
username string  Optional //Username policy is defined in Moodle security config.
... //more optional strings
customfields  Optional //User custom fields (also known as user profil fields)
list of ( 
object {
type string   //The name of the custom field
value string   //The value of the custom field
} 
)preferences  Optional //User preferences
list of ( 
object {
type string   //The name of the preference
value string   //The value of the preference
} 
)} 
)
以及:

REST(POST参数)


所以我想这就是我的HTTP请求:

auto NetworkPostRequest = QNetworkRequest(QUrl("http://XXX.XXX.XXX.XXX/webservice/rest/server.php?wstoken=XXXXXXXXX&moodlewsrestformat=json&wsfunction=core_user_update_users" ));
NetworkPostRequest.setHeader(QNetworkRequest::ContentTypeHeader,"application/x-www-form-urlencoded");

QByteArray Data;
Data.append("users[0][id]=12");
Data.append("&users[0][firstname]=QtTestname");
this->NetworkAccessManager->put(NetworkPostRequest, Data);


但我从moodle那里得到以下信息:

{
    "debuginfo": "Missing required key in single structure: users",
    "errorcode": "invalidparameter",
    "exception": "invalid_parameter_exception",
    "message": "Invalid parameter value detected"
}


很明显,数据有问题,但我想不出来。希望这里有人能帮上忙。

解决方案是在数据的第一个附加中添加一个“&”

QByteArray Data;
Data.append("&users[0][id]=12");
Data.append("&users[0][firstname]=QtTestname");
this->NetworkAccessManager->put(NetworkPostRequest, Data);
没有数组作为参数的Moodle函数不关心这个问题,所以直到现在我才注意到它

QByteArray Data;
Data.append("&users[0][id]=12");
Data.append("&users[0][firstname]=QtTestname");
this->NetworkAccessManager->put(NetworkPostRequest, Data);