1. 程式人生 > >QT QHttp 訪問 WEBSERVICE 範例

QT QHttp 訪問 WEBSERVICE 範例

        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);