2013-05-01 67 views
0

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

谢谢。

+0

你的问题是混乱的,你可以请澄清你正在努力做得更好。 – skrilled 2013-05-01 23:16:36

+0

您可能正在寻找'fopen($ url);'或类似的东西,但没有更多细节,很难确定。 – 2013-05-01 23:18:39

+0

你的意思是你正在尝试生成一个帖子来运行一个PHP脚本,它将返回一些数据(以json格式),以便您可以在导致POST发生的页面中使用它。如果阅读AJAX并让生活更轻松,请查阅jQuery(一个JavaScript框架) – RiggsFolly 2013-05-01 23:21:20

回答

0

假设你正在试图获得一个JSON文件,并把它变成一个数组:

$content = file_get_contents('http://www.example.com/test.json'); 
$json_array = json_decode($content); 
print_r($json_array) 
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();