简体   繁体   English

将api转换为PHP获取格式

[英]translate api to PHP get format

I'm a beginner in web design and I was trying this API 我是Web设计的初学者,正在尝试使用此API
http://docs.imagga.com/ http://docs.imagga.com/

and it mention that auto-tagging need to use get request 并提到自动标记需要使用get请求
and it give this: 它给出了:

http://i.imgur.com/E2zEUrm.png -> it's a screen shot picture ->这是屏幕截图

but I have no idea how to send request 但我不知道如何发送请求

(after I saw the below answer given by Barmar) I have tried to type this code: (在看到Barmar提供的以下答案之后),我尝试键入以下代码:

 $(document).ready(function(){
jQuery.ajax({
    url: 'http://api.imagga.com/v1/tagging',         
    type: "GET",                          
    data: { url: 'http://upload.wikimedia.org/wikipedia/commons/9/95/Mountain-bike-racing.jpg'} ,
    beforeSend: function(xhr) {
        xhr.setRequestHeader ("Authorization", " Basic my key");
    },
    success: function(response) {
            alert(response);
        }

});  });

but it comes to show that 但这表明

thanks for your help 谢谢你的帮助

It should be something like this: 应该是这样的:

$(document).ready(function(){
    $.ajax({
        url: 'http://api.imagga.com/v1/tagging',         
        type: "GET",                          
        data: { url: 'http://upload.wikimedia.org/wikipedia/commons/9/95/Mountain-bike-racing.jpg',
        beforeSend: function(xhr) {
            xhr.setRequestHeader ("Authorization", "Basic YourAPIKey");
        },
        success: function(response) {
                alert(response);
        }
    });
});

You use the data: parameter to set URL parameters in GET requests. 您可以使用data:参数在GET请求中设置URL参数。 To implement authentication, you have to add an Authorization header, this is done using the Javascript setRequestHeader method on the XHR object. 要实现身份验证,您必须添加一个Authorization标头,这是使用XHR对象上的Javascript setRequestHeader方法完成的。

I figured this question 我想到了这个问题

the index.html file looks like index.html文件看起来像

 $("button").click(function(){
$.get('post_url.php', function(rep){

and the post_url.php looks like 和post_url.php看起来像

 function send_post($url){
$options = array(
    'http' => array(
        'method' => 'GET',
        'header' => 'Authorization: Basic key \r\n'
    )
);
$context = stream_context_create($options);
$result = file_get_contents($url, false, $context);

return $result;
};

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM