问题描述
我有一个 qt 应用程序,我想用我的应用程序向 Web 服务发送请求。我的内容长度不是常数,所以我在另一个函数上计算它并在必要时调用它,我的主机是运行我的应用程序的同一网络上的 IIS 服务器。这是我的代码示例。
uint32_t MainWindow::contentLenghtCalculator(QString unique_ID,bool status)
{
QString status_str ;
QString password = "password";
if(status){
status_str = "true";
}
else{
status_str = "false";
}
this->globalRequest =
"<?xml version=\"1.0\" encoding=\"utf-8\"?>"
"<soap:Envelope xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" "
"xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" "
"xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\">"
"<soap:Body>"
"<Control xmlns=\"http://www.tempuri.org\">"
"<Number>";
this->globalRequest.append(unique_ID).append("</Number><ConnStatus>");
this->globalRequest.append(status_str).append("</ConnStatus><Pass>");
this->globalRequest.append(password).append("</Pass>");
this->globalRequest.append("</Control>"
"</soap:Body>"
"</soap:Envelope>");
return this->globalRequest.size() ;
}
发送网络服务请求的函数:
void MainWindow::webServiceRequest()
{
qnetworkrequest request;
QNetworkAccessManager manager;
int content_lenght = this->contentLenghtCalculator(this->unique_id,this->connectStatus);
QString cont_length = QString::number(content_lenght);
request.setRawHeader("Content-Type","text/xml; charset=utf-8");
request.setRawHeader("Content-Lenght",cont_length.toUtf8());
request.setRawHeader("SOAPAction","http://tempuri.org/Control");
request.setUrl(QUrl("IISserverName.firm.firm/outsourceappfuncs/WebService.asmx"));
QNetworkReply* reply = manager.post(request,this->globalRequest.toUtf8());
QEventLoop eventLoop;
QObject::connect(reply,SIGNAL(finished()),&eventLoop,SLOT(quit()));
eventLoop.exec();
if (reply->error() != QNetworkReply::NoError)
qDebug() << "Network error: " << reply->error();
else
qDebug() << reply->readAll();
}
我对网络领域了解不多。我得到的错误是 QNetworkReply::ProtocolUnkNownError。我试图从那个问题中写出类似 QUrl 的答案:ProtocolUnknownError upon sending SOAP request in Qt 但我仍然遇到同样的错误。任何帮助都将得到认可。谢谢!
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)