第一次接触xml格式请求,因为我们公司要对接其他公司的平台,需要用XML格式进行请求,才可以打通内网访问,
在网上查了好多资料也没明白这个格式怎么使用,试了多次,发现用模板字符串将请求内容包裹进去就可以使用,废话不多说,直接上代码
//此处是请求参数
let add2 =
`<?xml version="1.0" encoding="UTF-8" ?>
<instance>
<status>UP</status>
<port enabled="true">8889</port>
<securePort enabled="false">443</securePort>
<dataCenterInfo class="com.netflix.appinfo.InstanceInfo">
<name>MyOwn</name>
</dataCenterInfo>
<leaseInfo>
<renewalIntervalInSecs>300</renewalIntervalInSecs>
<durationInSecs>9000</durationInSecs>
</leaseInfo>
<vipAddress></vipAddress>
<secureVipAddress></secureVipAddress>
</instance>`;
//这里axios请求
this.$axios
.post(
"http://183.207.196.25:50087/ga/xh-registry-center/eureka/apps/gzlprocessserver",
add2,//直接将xml放到此处
{
headers: {
//根据接扣文档需要加的请求头
"Content-Type": "application/xml"
},
}
)
.then(function (response) {
console.log(response);
})
.catch(function (error) {
console.log(error);
});
有不足之处请指出,也可以多进行交流,本人经常在线,
如果对你有用的话,希望来个关注