QT QHttp 訪問 WEBSERVICE 範例
阿新 • • 發佈:2019-02-04
QUrl url(urlLineEdit->text());
QHttpRequestHeader header("POST", url.path() );
header.setValue("Host", url.host() );
header.setContentType("text/xml; charset=utf-8");
header.setValue("SOAPAction", ""http://tempuri.org/HelloWorld"");
QString content("<?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>"
" <HelloWorld xmlns="http://tempuri.org/">sdafwer</HelloWorld>"
" </soap:Body>"
"</soap:Envelope>"
);
//header.setValue("Content-Length", tr("%1").arg(11) );
http ->setHost( url.host() );
httpRequestAborted =false;
httpGetId = http->request( header, content.toUtf8 (), buffer);
QHttpRequestHeader header("POST", url.path() );
header.setValue("Host", url.host() );
header.setContentType("text/xml; charset=utf-8");
header.setValue("SOAPAction", ""http://tempuri.org/HelloWorld"");
QString content("<?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/">
" <HelloWorld xmlns="http://tempuri.org/">sdafwer</HelloWorld>"
" </soap:Body>"
"</soap:Envelope>"
);
//header.setValue("Content-Length", tr("%1").arg(11) );
http
httpRequestAborted =false;
httpGetId = http->request( header, content.toUtf8 (), buffer);