【问题标题】:How to Curl from Mashape in PHP如何在 PHP 中从 Mashape 卷曲
【发布时间】:2014-10-24 00:30:52
【问题描述】:

我有以下 curl 代码来检查号码是否已激活免打扰。但我不知道如何使用这个。我如何在 php 中实现这一点以获取 json 输出。

CURL 代码:

curl --get --include "https://dndcheck.p.mashape.com/index.php?mobilenos=9999999999%2C8888888888" \
  -H "X-Mashape-Key: g5Svg3wHuomshHIyjncC0hetIUVXp1h7E0LjsnJmorZlVxUcQV"

API 和文档的链接: https://www.mashape.com/blaazetech/dnd-check

【问题讨论】:

  • 感谢 Mashape 密钥。

标签: php curl mashape


【解决方案1】:

试试这个,告诉我它是如何为你工作的:

<?php
// Create a stream
$opts = array(
  'http'=>array(
    'method'=>"GET",
    'header'=>"X-Mashape-Key: g5Svg3wHuomshHIyjncC0hetIUVXp1h7E0LjsnJmorZlVxUcQV"               
  )
);

$context = stream_context_create($opts);

// Open the file using the HTTP headers set above
$res = file_get_contents('https://dndcheck.p.mashape.com/index.php?mobilenos=9999999999%2C8888888888', false, $context);
print_r(json_decode($res, true));
?>

希望这足以让您入门。
在实践中我猜你将不得不通过变量获取密钥和电话号码,但这很简单。

【讨论】:

  • 发布没有任何解释的解决方案对任何人都没有帮助,您能否发布为什么您的代码有效以及您为什么使用这种方法?
  • @MihaiIorga 我很乐意对代码的每一行进行大量解释,但这不是 OP 所要求的。这是他的问题:How can i implement this in php to get json output。否则你是对的 - 以身作则并不总是最好的事情......除非我们谈论的是领导力:)
  • 是的,但您没有使用curl,因此您的回答无效,如果您将其视为 OP 所要求的 :)
  • @MihaiIorga 实际上我首先准备了curl 的答案,然后决定反对,希望file_get_contents 方法更容易理解。同样通过这种方式,该解决方案无需依赖 curl 模块即可工作。但无论如何,为了完整起见,我也会包含 curl 方法。
  • @MihaiIorga 想将其用于我的网站。它用于检查手机号码是否已激活(印度号码)..
猜你喜欢
  • 2017-07-21
  • 2015-06-03
  • 2018-02-23
  • 1970-01-01
  • 2012-06-28
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-09-18
相关资源
最近更新 更多