解析多部分/相关响应并将附件保存到文件

时间:2018-05-15 06:18:35

标签: node.js mime

我做了一个简单的POST,返回下面的内容。我期待一个.txt.gz文件。我需要知道如何检索附件。我在编写文件之前尝试创建缓冲区,分隔符和拆分,但它总是回来时已损坏。

请求库解释了如何使用附件的PUT请求,而不是如何使用响应消息。

有人可以帮忙吗?已经有一个星期了。

JSON.stringify(RES)

{
    "statusCode": 200,
    "body": {
        "type": "Buffer",
        "data": [
            13,
            10,
            45,
            45(..truncated)
        ]
    },
    "headers": {
        "set-cookie": [
            "JSESSIONIDSSO=982EF51351B9497045DB6AB5A2D50DBF; Path=/; Secure; HttpOnly",
            "JSESSIONID=995EF8A4A893860159CE463582E4CDDD; Path=/logcollectionservice; Secure; HttpOnly",
            "SoapSession.id=-2851099334472488788"
        ],
        "x-frame-options": "SAMEORIGIN",
        "strict-transport-security": "max-age=31536000; includeSubdomains",
        "content-type": "multipart/related; type=\"text/xml\"; start=\"<852C508C64251E692C9217DFA4EB7433>\"; boundary=\"----=_Part_109_17473961.1526352793275\"",
        "transfer-encoding": "chunked",
        "date": "Tue, 15 May 2018 02:53:13 GMT",
        "connection": "close",
        "server": ""
    },
    "request": {
        "uri": {
            "protocol": "https:",
            "slashes": true,
            "auth": null,
            "host": "50.22.22.22:8443",
            "port": "8443",
            "hostname": "50.22.22.22",
            "hash": null,
            "search": null,
            "query": null,
            "pathname": "/logcollectionservice/services/DimeGetFileService",
            "path": "/logcollectionservice/services/DimeGetFileService",
            "href": "https://50.22.22.22:8443/logcollectionservice/services/DimeGetFileService"
        },
        "method": "POST",
        "headers": {
            "Authorization": "Basic YWRt123123123123123123",
            "SOAPAction": "http://schemas.cisco.com/ast/soap/action/#LogCollectionPort#GetOneFile",
            "content-length": 467
        }
    }
}

res.body

------=_Part_183_12814895.1526363698144
Content-Type: text/xml; charset=UTF-8
Content-Transfer-Encoding: binary
Content-Id: <5DDAB109C3B14685FF6B0EA83D2CF8E4>

<?xml version="1.0" encoding="UTF-8"?><soapenv:Envelope 
xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" 
xmlns:xsd="http://www.w3.org/2001/XMLSchema" 
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"><soapenv:Body> 
<ns1:GetOneFileResponse 
soapenv:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" 
xmlns:ns1="http://schemas.cisco.com/ast/soap/"><DataHandler 
href="cid:36F92AA211EE04B422D4B07AB07D841A" xsi:type="ns2:DataHandler" 
xmlns:ns2="DimeGetFileService"/></ns1:GetOneFileResponse> 
</soapenv:Body></soapenv:Envelope>

------=_Part_183_12814895.1526363698144
Content-Type: application/octet-stream
Content-Transfer-Encoding: binary
Content-Id: <36F92AA211EE04B422D4B07AB07D841A>

����o�:���W��U����<��퐖.�I��8!h�0�l��?~���m�z��;'����>��oL���'Ϗ��3  
'�tSV�EO�8zÂ���[a0����.��`�4wbO�q��FI���:�n܍>��e- 
��!^@"�U5��;��^����U[V���s˽��q_��̣
����{gm����r��
���c��㬌Pf]Z�����cs���#ߵ� (truncated)

------=_Part_183_12814895.1526363698144--

0 个答案:

没有答案