【问题标题】:Get Request to an API url获取对 API url 的请求
【发布时间】:2013-07-17 18:59:34
【问题描述】:

我已经注册了同义词 API.. 见 the details on this page

我无法在我的 php 代码中实现这一点。

如果我将链接复制并粘贴到网络浏览器中,我可以看到结果没有问题。

我希望在链接中包含一个带有相关单词的变量,而不是手动输入单词,即$variable_with_word_stored,如下所示。

    http://words.bighugelabs.com/api/2/xxxxxxxx/$variable_with_word_stored/php 

    //format could be php (I would unserialize)..or json..I could decode it?

有什么想法吗?谢谢。

【问题讨论】:

    标签: php api get synonym


    【解决方案1】:

    听起来你的意思是你想要调用该网页的结果并将其存储在一个变量中。您应该做的是在代码中向该页面发送一个 http get 请求。

    使用 curl 和 php 查看,你可以向你请求的 url 发送一个 http 请求,捕获结果并通过 json_decode 解析它

    http://php.net/manual/en/curl.examples-basic.php

    【讨论】:

      【解决方案2】:

      试试这样,也许你不需要 curl:

      $key = "xxxxxxxx";
      $word = "love";
      
      echo file_get_contents("http://words.bighugelabs.com/api/2/$key/$word/php");
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2016-11-09
        • 2016-03-16
        • 1970-01-01
        • 2018-07-28
        相关资源
        最近更新 更多