当我在浏览器中打开页面时,我得到的是:
{"id":"786938997027","name":"users","isSystem":false,"status":3,"type":2,"error":false,"code":200}
当我从代码发送请求时,我得到下一个输出:
Response: {"error":true,"code":400,"errorNum":1208,"errorMessage":"name must be non-empty"}
怎么了?
void foo()
{
string url = "http://localhost:8529/_db/testdb/_api/collection/users";
import std.experimental.logger;
globalLogLevel(LogLevel.info);
Json users;
requestHTTP(url,
(scope req) {
req.method = HTTPMethod.POST;
},
(scope res) {
logInfo("Response: %s", res.bodyReader.readAllUTF8());
users = res.bodyReader.readAllUTF8();
}
);
}
您需要使用GET类型的请求,如前面提到的@Colonel Thirty Two。所以去掉这行:
req.method = HTTPMethod.POST;
或将其更改为:
req.method = HTTPMethod.GET;