如何使用QNetworkAccessManager发送DELETE请求?

时间:2014-02-04 09:51:55

标签: c++ qt rest qnetworkaccessmanager

我正在使用QNetworkAccessManager从服务器发送POST,PUT和GET数据。代码如下所示。

QNetworkAccessManager *manager = new QNetworkAccessManager(this);

connect(manager, SIGNAL(proxyAuthenticationRequired(const QNetworkProxy &, QAuthenticator *)), 
  SLOT(slotProxyAuthenticationRequired(const QNetworkProxy &, QAuthenticator *)));
connect(manager, SIGNAL(authenticationRequired(QNetworkReply *, QAuthenticator *)), 
  SLOT(slotAuthenticationRequired(QNetworkReply *, QAuthenticator *)));

QNetworkRequest request;

request.setUrl(m_url);
request.setRawHeader("User-Agent", "Qt NetworkAccess 1.3");

m_pReply = manager->get(request);
m_pReply = manager->post(request,"name=someName");
m_pReply = manager->put(request,"name=someName");

我无法找到请求的任何删除方法。是的,我找到了manager-> deleteResource(request)

但是有没有

manager->delete(request,"name=someName")
Qt中的

方法?或者是否存在基于例如姓名删除数据的其他方法?

1 个答案:

答案 0 :(得分:2)

由于delete是C ++中的保留字,因此QNetworkAccessManager的相应方法称为deleteResource

http://qt-project.org/doc/qt-5.0/qtnetwork/qnetworkaccessmanager.html#deleteResource