小编Lau*_*uri的帖子

使用 Qt 的 RESTful API 请求

我正在尝试从此链接中找到示例以使其工作。

GETandDELETE方法正在起作用,但我对PUTand有一些问题POST。我得到服务器回复:Bad Request。随着qDebug()我得到这个错误:

QNetworkReply::NetworkError(ProtocolInvalidOperationError)

对于httprequestworker.cpp,我已将请求类型更改为:

request_content.append("Content-Type: application/fhir+json");
Run Code Online (Sandbox Code Playgroud)

这是我从计算机获取 JSON 文件内容并为服务器执行整个请求输入的函数:

void MainWindow::on_pushButton_clicked()
{
    QString url_str = "http://hapi.fhir.org/baseDstu3/Patient/4705560";

    HttpRequestInput input(url_str, "PUT");

    QString settings;
    QFile file;

    file.setFileName("C:/Users/Lauri/Desktop/FHIR/Omia testeja/themostsimplepatientJSON.json");
    file.open(QIODevice::ReadOnly | QIODevice::Text);
    settings = file.readAll();
    file.close();

    settings.remove(QRegExp("[\\n]"));
    qDebug() << settings;
    settings.toUtf8();
    input.add_var("key1", settings);


    HttpRequestWorker *worker = new HttpRequestWorker(this);
    connect(worker, SIGNAL(on_execution_finished(HttpRequestWorker*)), this, SLOT(handle_result(HttpRequestWorker*)));
    worker->execute(&input);
}
Run Code Online (Sandbox Code Playgroud)

这是我要上传的简单 JSON:

{
  "resourceType": "Patient",
  "text": {
    "status": "generated",
    "div": "<div xmlns='http://www.w3.org/1999/xhtml'>This is a …
Run Code Online (Sandbox Code Playgroud)

c++ qt httprequest hl7-fhir hapi-fhir

8
推荐指数
1
解决办法
1万
查看次数

标签 统计

c++ ×1

hapi-fhir ×1

hl7-fhir ×1

httprequest ×1

qt ×1