0

我需要在我的代码中创建一个新的 PHP HTTP 请求。它返回一个 json 编码的数据数组。如何创建新的 HTTP 请求而不重定向到该位置?

谢谢。

4

2 回答 2

0

这就是你要找的东西:http ://codular.com/curl-with-php

// Get cURL resource
$curl = curl_init();
// Set some options - we are passing in a useragent too here
curl_setopt_array($curl, array(
    CURLOPT_RETURNTRANSFER => 1,
    CURLOPT_URL => 'http://stackoverflow.com'
));
// Send the request & save response to $resp
$resp = curl_exec($curl);
// Close request to clear up some resources
    curl_close($curl);


//For testing only
print_r('<pre>');
print_r($resp);die();
于 2013-05-02T00:20:22.413 回答
0

假设您正在尝试获取 json 文件并将其放入数组中:

$content = file_get_contents('http://www.example.com/test.json');
$json_array = json_decode($content);
print_r($json_array)
于 2013-05-01T23:26:05.463 回答