gpt4 book ai didi

javascript - Mailchimp Javascript 请求

转载 作者:行者123 更新时间:2023-11-30 21:11:46 25 4
gpt4 key购买 nike

我有来自 mailchimp 文档的 curl 示例请求,但我是新手,无法将其转换为 javascript 函数

curl --request POST \
--url 'https://usX.api.mailchimp.com/3.0/lists/57afe96172/members' \
--user 'anystring:apikey' \
--header 'content-type: application/json' \
--data '{"email_address":"urist.mcvankab+3@freddiesjokes.com", "status":"subscribed"}' \
--include

谁能帮帮我?

我也有这个并且可以从浏览器 url 工作

https://us14.api.mailchimp.com/2.0/lists/subscribe.json?apikey=xxxxxxxxxxx&id=xxxxxxxx&email[email]=xxxxxxx&send_welcome=true

或者如何转换这个?

最佳答案

按照这些思路可能会起作用:

const xmlHttp = new XMLHttpRequest();
xmlHttp.onreadystatechange = () => {
try {
if (xmlHttp.readyState !== 4) return;
if (xmlHttp.status !== 200)
throw new Error(
xmlHttp.statusText || 'HTTP STATUS ' + xmlHttp.status
);
console.log(xmlHttp.responseText);
} catch (err) {
console.error(err);
}
};
xmlHttp.open('POST', 'https://usX.api.mailchimp.com/3.0/lists/57afe96172/members');
xmlHttp.setRequestHeader('Authorization', 'Basic ' + btoa('anystring' + ':' + 'apikey'));
xmlHttp.setRequestHeader('content-type', 'application/json');
xmlHttp.send('{"email_address":"urist.mcvankab+3@freddiesjokes.com", "status":"subscribed"}');

关于javascript - Mailchimp Javascript 请求,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46060928/

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