curl ajax 区别,将cURL命令转换为ajax

我试图使用由网站提供的zoom.us API。他们给我卷曲命令来创建一个新用户:将cURL命令转换为ajax

curl --data 'api_key=your_api_key&api_secret=your_api_secret&[email protected]&type=1&first_name=John&last_name=Smith' https://api.zoom.us/v1/user/create

我翻译成AJAX:

$.ajax({

url: 'https://api.zoom.us/v1/user/create',

type: "POST",

cache: true,

async: false,

headers: {

'Content-Type': 'application/json'

},

data: JSON.stringify({ 'api_key': 'key', 'api_secret': 'secret', 'email': '[email protected]', 'first_name': 'John', 'last_name': 'Smith' }),

success: function (res) {

console.log(res);

},

error: function (err) {

console.error(err);

}

});

(注:“API_KEY”和“api_secret”的变量只是在上面的占位符例如,我有我自己的密钥和秘密,我试图使这个API调用时使用)

但是,此代码不适用于我。我得到以下403错误:

XMLHttpRequest cannot load https://api.zoom.us/v1/user/create.

Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource.

Origin 'http://mywebsite.com' is therefore not allowed access. The response had HTTP status code 403.

我的问题是这样的:我做错了什么?我错误翻译了什么吗?此外,我知道类似的问题之前已经被问到(这是我如何提出我的翻译代码上面),但他们无法解决我的问题

ETA:后apokryfos的评论,这是我更新的代码:

$.ajax({

url: 'https://api.zoom.us/v1/user/create',

cache: true,

async: false,

data: { 'api_key': 'key', 'api_secret': 'secret', 'email': e, 'first_name': 'john', 'last_name': 'smith' },

success: function (res) {

console.log(res);

},

error: function (err) {

console.error(err);

}

});

产生一个新的405错误:

XMLHttpRequest cannot load api.zoom.us/v1/user/create?api_key=key&api_secret =secret&email=test%40email.com&first_name=Juan&last_name=Gon‌​zalez.

No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'website.com'; is therefore not allowed access.

2016-08-24

Juan

+2

POST数据和JSON数据是不一样的东西。你应该传递这个对象,而不要对它进行加密。也不要更改内容类型。 –

+3

更常称为CORS(跨源资源共享)。如果你在每台客户端机器上放置API key/secrets,我会认为你做错了。 –

+0

感谢@apokryfos,解决了我的403错误,但现在我得到了一个新的405错误:XMLHttpRequest无法加载https://api.zoom.us/v1/user/create?api_key=key&api_secret = secret&email = test%40email.com&first_name =涓&姓氏=冈萨雷斯。请求的资源上没有“Access-Control-Allow-Origin”标题。 Origin'http://website.com'因此不被允许访问。该响应的HTTP状态码为405. –

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值