1

我在 PHP 中使用 API。我必须将数据推送到这个 API 中。例如,如果我访问http://www.api.com/api.php?data=mydata,我会将“mydata”推送到 api。

事实上,我想使用 PHP 在 URL 栏中输入数据(这可能非常好哈哈)

提前致谢 !

4

3 回答 3

4

你需要这个吗?

$URL = "http://www.api.com/api.php?data=mydata";
$data = file_get_contents($URL);

data 现在包含响应。

于 2013-03-07T14:20:50.443 回答
4

你试过看卷曲吗?http://php.net/manual/en/book.curl.php

例子:

$ch = curl_init();// init curl
curl_setopt($ch, CURLOPT_URL,"http://www.api.com/api.php");
curl_setopt($ch, CURLOPT_POST, 1);// set post data to true
curl_setopt($ch, CURLOPT_POSTFIELDS,"data=mydata&foo=bar");// post data

// receive server response ...
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);// gives you a response from the server

$response = curl_exec ($ch);// response it ouputed in the response var

curl_close ($ch);// close curl connection
于 2013-03-07T14:32:46.473 回答
1

您需要发布数据吗?查看 http_post_data :

http://php.net/manual/en/function.http-post-data.php

于 2013-03-07T14:23:57.010 回答