<?php
function post($url,$parameter="",$referer="",$cookies="")
{
    /*
        $parameter 格式为:aa=1&bb=2
        $cookies 格式为:aa=1;bb=2
    */
    $returnResult = array();
    $returnResult["content"] = false;
    $returnResult["cookies"] = false;
    $context['http'] = array   
    (   
        'method' => 'POST',
        'header'=>"Content-type: application/x-www-form-urlencoded\r\n".   
        "User-Agent:Mozilla/5.0 (Windows; U; Windows NT 5.1; zh-CN; rv:1.9.0.11) Gecko/2009060215 Firefox/3.0.11\r\n" .
        "Cookie:{$cookies}\r\n" . 
        "Referer:{$referer}\r\n" .
        "Content-Length:100\r\n" .
        "\r\n",
        'content' => $parameter
    );
    echo file_get_contents($url,false,stream_context_create($context));
}
post("http://www.lishirenwu.com.cn/");
?>历史故事
Warning: file_get_contents(http://www.lishirenwu.com.cn/) [function.file-get-contents]: failed to open stream: HTTP request failed! HTTP/1.1 405 Method Not Allowed in F:\cc\index.php on line 22

解决方案 »

  1.   

    file_get_contents函数引起的问题。有些主机服务商把php的allow_url_fopen选项是关闭了,就是没法直接使用file_get_contents来获取远程web页面的内容。那就是可以使用另外一个函数curl具体解决方案自己可以去网上搜索。如果有条件的话,就自己修改php.ini,将allow_url_fopen打开。
      

  2.   

    楼上解释不错 
    failed to open stream 修改一下php.ini文件