【发布时间】:2021-09-19 18:21:06
【问题描述】:
我今天向您报告,并礼貌地通知我被指示,我在尝试发送 API 请求时很乐意这样做。是的,我知道,有权利在网上提供有关 JS / AJAX / JQuery 的信息,虽然它通常涉及读取 API,因此它适用于一个 API 功能。下面是代码:
当然,我故意更改了 API 密钥,所以这不是问题,密钥本身就可以。 ;)
<script>
UserAction () {
var xhr = new XMLHttpRequest ();
xhr.onreadystatechange = function () {
if (this.readyState == 4 && this.status == 200) {
// Common Action To Take When Document is ready:
var answer = xhr.responseText;
console.log ("ok" + response);
}
};
xhr.open ('POST', 'https: //api5.esv2.com/v2/Api/Subscribers/', true);
xhr.send ("POST https://api5.esv2.com/v2/Api/Subscribers/ HTTP / 1.1 Content-Type: text / xml <ApiRequest xmlns: xsi = \" http://www.w3.org/ 2001 / XMLSchema-instance \ "xmlns: xs = \" http: //www.w3.org/2001/XMLSchema \ "> <ApiKey> KEY </ApiKey> <xsi data: type = \" Subscriber \ "> < Mode> AddAndUpdate </Mode> <Force> true </Force> <ListId> 1 </ListId> <Email> jan.kowalski@domena.com </Email> <Firstname> Jan </Firstname> <Lastname> Kowalski < /Lastname><TrackingCode>123</TrackingCode><Vendor>xyz</Vendor><Ip>11.22.33.44</Ip><Properties><Property><Id>5</Id><Value xsi: type = \ "xs: string \"> student </Value> </Property> <Property> <Id> 3 </Id> <Value xsi: type = \ "xs: dateTime \"> 1985-03-12 </Value> </Property></Properties></Data> </ApiRequest> ");
}
【问题讨论】:
标签: javascript api rest post