Mailchimp Javascript 请求
Mailchimp Javascript request
我有来自 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"}');
我有来自 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"}');