如何在PHP中从Mashape中卷曲
我有下面的curl代码来检查一个数字是否被DND激活。但我不知道怎么用这个。如何在php中实现这一点以获得json输出 卷曲代码:如何在PHP中从Mashape中卷曲,php,curl,mashape,Php,Curl,Mashape,我有下面的curl代码来检查一个数字是否被DND激活。但我不知道怎么用这个。如何在php中实现这一点以获得json输出 卷曲代码: curl --get --include "https://dndcheck.p.mashape.com/index.php?mobilenos=9999999999%2C8888888888" \ -H "X-Mashape-Key: g5Svg3wHuomshHIyjncC0hetIUVXp1h7E0LjsnJmorZlVxUcQV" 链接到api和文档:
curl --get --include "https://dndcheck.p.mashape.com/index.php?mobilenos=9999999999%2C8888888888" \
-H "X-Mashape-Key: g5Svg3wHuomshHIyjncC0hetIUVXp1h7E0LjsnJmorZlVxUcQV"
链接到api和文档:
试试这个,告诉我它是如何为您工作的:
<?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));
?>
希望这足以让您开始学习。在实践中,我想你将不得不制作一个变量获得的密钥和电话号码,但这很琐碎。发布解决方案而不做任何解释对任何人都没有帮助,你能发布你的代码为什么工作以及为什么使用这种方法吗?@mihaiorga我很乐意对代码的每一行都做大量解释,然而,这不是OP所问的。这又是他的问题:
我如何在php中实现这一点以获得json输出
。否则你是对的-以身作则并不总是最好的。。。除非我们谈论的是领导力:)是的,但你没有使用curl
,因此你的答案不可能是有效的,如果你认为这是OP所问的:)@mihaiorga实际上首先我用curl
准备了答案,然后决定不使用,希望file\u get\u contents
方法更容易理解。同样,这种解决方案也可以在不依赖curl模块的情况下工作。但无论如何,为了完整性,我也会包括curl方法。@MihaiIorga想在我的网站上使用它。它用于检查手机号码是否已激活dnd(印度号码)…感谢您提供的Mashape密钥。