我的任務是生成格式錯誤的 SOAP 請求并檢查我收到的錯誤回應型別。
例如:
const payload = `
<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope
xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:test="urn:TEST"
>
<soap:Body>
<test:GetOperatingDataValues
xmlns:test="urn:TEST"
>
<test:ListId>1</test:ListId>
</test:GetOperatingDataValues>
</soap:Body>
</soap:Envelope>`
現在,如果我將上述請求正文發送到后端服務器,例如:
const 結果 = axios.post("backendServer", 有效載荷)
console.log(result) 將給出來自后端的回應(在這種情況下,來自 ListId 1 的 GetOperatingDataValues 函式的回應)
現在,我必須以不同的方式修改該有效負載,例如洗掉結束標簽、不同的開始和結束標簽名稱、從任何標簽中洗掉“<”,或從結束標簽中洗掉“/”、不同的方法名稱等,然后發送有效負載并檢查錯誤回應。
有什么方法可以將格式正確的 xml 修改為格式錯誤的 xml(在節點 js 中)。我瀏覽過不同的包,例如 xml2js、fast-xml-parser。但這些包只是形成正確的 xml。
任何幫助將不勝感激。
uj5u.com熱心網友回復:
我會認為很明顯,要創建非 XML 檔案,您不想使用 XML 工具。只需將 XML 視為字串并應用正則運算式,例如替換</
為<
.
轉載請註明出處,本文鏈接:https://www.uj5u.com/ruanti/471893.html