QML xmlhttprequest和curl获得不同的结果

时间:2020-02-11 19:24:56

标签: qt qml

我正在尝试使用xmlhttprequest在QML中获得肥皂响应。 (我知道qml xhr是不同的)。当我用curl运行它时,我得到的正是我想要的。

curl -u user:pass https://outlook.office365.com/ews/exchange.asmx -d "@ews.xml" -H "Content-Type:text/xml" | xmllint --format -

这是基本身份验证,ews.xml与QML中的以下var相同

function getEWS() {
    var user = ""
    var password = ""
    var xml = '<?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/" xmlns:m="http://schemas.microsoft.com/exchange/services/2006/messages" xmlns:t="http://schemas.microsoft.com/exchange/services/2006/types"><soap:Body><m:FindItem Traversal="Shallow"><m:ItemShape><t:BaseShape>IdOnly</t:BaseShape><t:AdditionalProperties><t:FieldURI FieldURI="folder:DisplayName" /><t:FieldURI FieldURI="item:Subject" /><t:FieldURI FieldURI="item:Importance" /><t:FieldURI FieldURI="item:HasAttachments" /><t:FieldURI FieldURI="item:DateTimeSent" /><t:FieldURI FieldURI="calendar:Location" /><t:FieldURI FieldURI="calendar:Organizer" /><t:FieldURI FieldURI="calendar:Start" /><t:FieldURI FieldURI="calendar:End" /></t:AdditionalProperties></m:ItemShape><m:CalendarView MaxEntriesReturned="5" StartDate="2020-02-01T00:00:00.000-05:00" EndDate="2020-03-01T00:00:00.000-05:00" /><m:ParentFolderIds><t:FolderId Id="AQAW" ChangeKey="AgAA" /></m:ParentFolderIds></m:FindItem></soap:Body></soap:Envelope>';
    var url = "https://outlook.office365.com/ews/exchange.asmx";
    var xmlhttp = new XMLHttpRequest();
    xmlhttp.open("GET", url, true, user, password);
    xmlhttp.onreadystatechange=function() {
        if (xmlhttp.readyState === 4 && xmlhttp.status === 200) {
            //console.log(xmlhttp.responseText.toString())
        }
        if (xmlhttp.readyState === xmlhttp.DONE) {
          console.log(xmlhttp.response, xmlhttp.responseXML, xmlhttp.status);
        }
    }
    //xmlhttp.setRequestHeader("Authorization", "Basic " + Qt.btoa(user + ":" + password));
    xmlhttp.setRequestHeader("Content-type", "text/xml");
    xmlhttp.send(xml);
}

我从xhr得到的响应是

<HTML lang="en"><HEAD><link rel="alternate" type="text/xml" href="
https://sn6pr06mb6447.namprd06.prod.outlook.com:444/EWS/Exchange.asmx?disco"/><STYLE
 type="text/css">#content{ FONT-SIZE: 0.7em; PADDING-BOTTOM: 2em;
MARGIN-LEFT: 30px}BODY{MARGIN-TOP: 0px; MARGIN-LEFT: 0px; COLOR:
#000000; FONT-FAMILY: Verdana; BACKGROUND-COLOR: white}P{MARGIN-TOP:
0px; MARGIN-BOTTOM: 12px; COLOR: #000000; FONT-FAMILY:
Verdana}PRE{BORDER-RIGHT: #f0f0e0 1px solid; PADDING-RIGHT: 5px;
BORDER-TOP: #f0f0e0 1px solid; MARGIN-TOP: -5px; PADDING-LEFT: 5px;
FONT-SIZE: 1.2em; PADDING-BOTTOM: 5px; BORDER-LEFT: #f0f0e0 1px solid;
PADDING-TOP: 5px; BORDER-BOTTOM: #f0f0e0 1px solid; FONT-FAMILY:
Courier New; BACKGROUND-COLOR: #e5e5cc}.heading1{MARGIN-TOP: 0px;
PADDING-LEFT: 15px; FONT-WEIGHT: normal; FONT-SIZE: 26px; MARGIN-
BOTTOM: 0px; PADDING-BOTTOM: 3px; MARGIN-LEFT: -30px; WIDTH: 100%;
COLOR: #ffffff; PADDING-TOP: 10px; FONT-FAMILY: Tahoma; BACKGROUND-
COLOR: #003366}.intro{display: block; font-size:
1em;}</STYLE><TITLE>Service</TITLE></HEAD><BODY><DIV id="content"
role="main"><h1 class="heading1">Service</h1><BR/><P class="intro">You have created a service.<P class='intro'>To test this service, you will need to create a client and use it to call the service. You can do this using the svcutil.exe tool from the command line with the following syntax:</P> <BR/><PRE>svcutil.exe <A HREF="
https://sn6pr06mb6447.namprd06.prod.outlook.com:444/EWS/Services.wsdl">https://sn6pr06mb6447.namprd06.prod.outlook.com:444/EWS/Services.wsdl</A></PRE></P><P
 class="intro">This will generate a configuration file and a code file that contains the client class. Add the two files to your client application and use the generated client class to call the Service. For
example:<BR/></P><h2 class='intro'>C#</h2><br /><PRE><font color="blue">class </font><font color="black">Test </font>{
<font color="blue">    static void </font>Main()
    {
        <font color="black">HelloClient</font> client = <font color="blue">new </font><font color="black">HelloClient</font>();

<font color="darkgreen">        // Use the 'client' variable to call
operations on the service.

</font><font color="darkgreen">        // Always close the client.
</font>        client.Close();
    }
}
</PRE><BR/><h2 class='intro'>Visual Basic</h2><br /><PRE><font color="blue">Class </font><font color="black">Test
</font><font color="blue">    Shared Sub </font>Main()
<font color="blue">        Dim </font>client As <font
color="black">HelloClient</font> = <font color="blue">New </font><font
color="black">HelloClient</font>()
<font color="darkgreen">        ' Use the 'client' variable to call
operations on the service.

</font><font color="darkgreen">        ' Always close the client.
</font>        client.Close()
<font color="blue">    End Sub
</font><font color="blue">End Class</font></PRE></DIV></BODY></HTML>

我还尝试了更改用户代理和其他标头,但它们没有任何区别。删除身份验证会给我一个401,所以我知道基本身份验证正在工作。我如何获得相同的结果

0 个答案:

没有答案