将CURL请求转换为AJAX请求

时间:2017-06-19 12:56:15

标签: ajax curl

我需要将以下CURL请求转换为HTML。该应用程序尚未在其网站上提供任何AJAX文档

curl -X GET --header "Accept: application/json" --header "user-key: 
xxxx" 
"https://developers.abcdef.com/api/v2.1/restaurant?res_id=000000"

到目前为止,我一直得到以下回复

{"code":403,"status":"Forbidden","message":"Invalid API Key"}

好吧,显然我没有说清楚。当我在应用程序网站上填写表格时,我得到了适当的回复。他们在代码框中给我回复和上面提到的CURL请求。

当我尝试使用AJAX实现它时,我得到了上面提到的响应

1 个答案:

答案 0 :(得分:-1)

your response {"code":403,"status":"Forbidden","message":"Invalid API Key"} clearly shows you are either missing api key / or sending invalid api key with the ajax request.

try after adding the api key to the below request format.

$.ajax({ method : 'GET', url : 'http://your-url.com', headers : { 'Accept' : 'application/json', 'user-key' : 'YOUR API KEY' }, success : function(data){ console.log(data); } });

相关问题