gpt4 book ai didi

javascript - sinon fakeserver 可以发送 xml 响应吗?

转载 作者:行者123 更新时间:2023-11-29 21:34:10 24 4
gpt4 key购买 nike

我想伪造一个以 xml 格式响应的服务器。我该怎么做?

     server.respondWith(
"GET",
"testurl",
[
200,
{
"Content-Type": "application/xml",
"Access-Control-Allow-Origin": "*",
"Cache-Control": "max-age=0, must-revalidate",
"Connection": "close"
},
<note></note>
]
);

最佳答案

当您使用 respondWith 模拟响应时,该方法的第三个参数是一个描述所需响应的数组。数组的第三个元素,其中有 <note></note>是响应的主体,因此您可以将 XML 作为字符串放在那里。

 var xml = getXmlStringSomehow();
server.respondWith(
"GET",
"testurl",
[
200,
{
"Content-Type": "application/xml",
"Access-Control-Allow-Origin": "*",
"Cache-Control": "max-age=0, must-revalidate",
"Connection": "close"
},
xml
]);

关于javascript - sinon fakeserver 可以发送 xml 响应吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35305673/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com