Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/kotlin/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 邮政数据及;显示源代码_Php - Fatal编程技术网

Php 邮政数据及;显示源代码

Php 邮政数据及;显示源代码,php,Php,我有个问题,是否可以先将数据发布到一个站点,然后获取我发布数据的站点的源代码 我试过这个: $html = file_get_contents('http://test.com/test.php?test=test'); 但是?test=test是$\u GET 所以,是的,我希望有人能帮助我!:)提前感谢(抱歉英语不好!)。您无法获取源代码,但您可以获取服务器提供的页面/输出。正如您提到的file\u get\u contents(),您可以使用它发送POST请求,但它看起来是这样的 //

我有个问题,是否可以先将数据发布到一个站点,然后获取我发布数据的站点的源代码

我试过这个:

$html = file_get_contents('http://test.com/test.php?test=test');
但是?test=test是$\u GET


所以,是的,我希望有人能帮助我!:)
提前感谢(抱歉英语不好!)。

您无法获取源代码,但您可以获取服务器提供的页面/输出。正如您提到的
file\u get\u contents()
,您可以使用它发送POST请求,但它看起来是这样的

// Create map with request parameters
$params = array ('surname' => 'Filip', 'lastname' => 'Czaja');

// Build Http query using params
$query = http_build_query ($params);

// Create Http context details
$contextData = array ( 
                'method' => 'POST',
                'header' => "Connection: close\r\n".
                            "Content-Length: ".strlen($query)."\r\n",
                'content'=> $query );

// Create context resource for our request
$context = stream_context_create (array ( 'http' => $contextData ));

// Read page rendered as result of your POST request
$result =  file_get_contents (
                  'http://www.sample-post-page.com',  // page url
                  false,
                  $context);

// Server response is now stored in $result variable so you can process it

示例来源:

您可以使用此函数的第三个参数:context

//编辑-小错误应该是:

$opts = array(
    'http' => array(
        'method' => "POST",
        'header' => "Connection: close\r\n".
                    "Content-type: application/x-www-form-urlencoded\r\n".
                    "Content-Length: ".strlen($postdata)."\r\n",
        'content' => $postdata
  )
);

尝试一篇curl帖子,您可以获取由请求生成的html,而不是使用curl的源代码。哦,很抱歉,这是因为我做了“echo$result”;但我现在得到了以下错误:注意:file_get_contents()[function.file get contents]:未指定内容类型假设应用程序/x-www-form-urlencodedLook再次在示例中,有不同的标题值。嗯。。。您的意思是什么,我如何更改它?我不知道您具体调用了什么,可能您的标题不正确。您应该添加“内容类型:application/x-www-form-urlencoded\r\n”。在标题中。
$opts = array(
    'http' => array(
        'method' => "POST",
        'header' => "Connection: close\r\n".
                    "Content-type: application/x-www-form-urlencoded\r\n".
                    "Content-Length: ".strlen($postdata)."\r\n",
        'content' => $postdata
  )
);