我想打电话给Citrix Rest API进行网络研讨会注册。
以下是API的网址:
https://api.citrixonline.com/G2W/rest/organizers/{organizerKey}/webinars/{webinarKey}/registrants
请求应该是POST,它应该有其他标题
"Accept", "application/json"
"Content-type", "application/json"
"Authorization", "OAuth oauth_token=ACCESSTOKEN"
我尝试对此API进行AJAX调用,但我收到了网络403错误
我的代码如下所示:
$.ajax({
url : url,
dataType : "jsonp",
headers: { "Content-Type":"application/json","Accept": "application/json","Authorization": "OAuth oauth_token=ACCESSTOKEN" },
type : 'POST',
contentType: "application/json",
data : {"firstName" : "FirstName", "lastName" : "lastNAme",
"email" : "abc@xyz.com"},
success : function (data) {
console.log(data);
},
error : function (data, errorThrown) {
alert(3);
}
});
请帮助!!
答案 0 :(得分:3)
根据jQuery ajax() documentation,
标题(默认:{})
类型:PlainObject
使用XMLHttpRequest传输与请求一起发送的其他标头键/值对的对象。始终添加标头X-Requested-With:XMLHttpRequest,但可以在此处更改其默认的XMLHttpRequest值。标题设置中的值也可以在beforeSend函数中覆盖。 (版本增加:1.5)
您可以根据Prestaul使用以下内容为您的请求设置标头:
// Request with custom header
$.ajax({
url: 'foo/bar',
headers: { 'x-my-custom-header': 'some value' }
});
确保您确实提供了正确的ACCESSTOKEN。
答案 1 :(得分:1)
您是否尝试将setRequestHeader
用作ajax调用的一部分?
xhr.setRequestHeader
以下示例:
$.ajax({
url : url,
dataType : "jsonp",
headers: { "Content-Type":"application/json","Accept": "application/json","Authorization": "OAuth oauth_token=ACCESSTOKEN" },
type : 'POST',
contentType: "application/json",
data : {"firstName" : "FirstName", "lastName" : "lastNAme", "email" : "abc@xyz.com"},
beforeSend : function( xhr ) {
xhr.setRequestHeader( "Authorization", "BEARER " + access_token );
},
success : function (data) {
console.log(data);
},
error : function (data, errorThrown) {
alert(3);
}
});
我希望它会有所帮助。
答案 2 :(得分:1)
你可以试试这个。
$.ajax({
url : url,
dataType : "jsonp",
headers: { "Content-Type":"application/json","Accept": "application/json","Authorization": "OAuth oauth_token=ACCESSTOKEN" },
type : 'POST',
contentType: "application/json",
data : {"firstName" : "FirstName", "lastName" : "lastNAme", "email" : "abc@xyz.com"},
beforeSend : function setHeader(xhr){
xhr.setRequestHeader('X-VN-ad', "sdd");
xhr.setRequestHeader('X-VN-APs', "mei");
}