简体   繁体   中英

PHP POST Data to HTTPS Fail with 404 error! Even with (CURL, fopen and file_get_contents)

All my efforts failed! I can't POST data to HTTPS Even by using CURL , fopen and file_get_contents !
I always getting a 404 error!
However, when I leech the page using GET method it open with no errors!
But when I using POST method for that page with its same URL it always fail with a 404 error!


My PHP code :

<?php
###########################################
    function curl_fopen_getContents( $functionName='curl', $method='GET' ) 
    {
        $post_data = http_build_query(array( 'a'   => '1' ));
        $cookies   = 'a=1';

        $opts = array('http' => array(
            'method'     => strtoupper($method), 
            'header'     => 
                            "Content-type: application/x-www-form-urlencoded\r\n"
                           ."Content-Length: " . strlen($post_data)."\r\n"
                           ."Cookie: $cookies\r\n",
            'content'    => $post_data,
            'timeout'    => 60
        ));
        $context = stream_context_create($opts);
        
        ///////////////////////////////////
        
        // you can decode it 
        $https_url = 'my_url_here';
        
        if( $functionName=='fopen' )
        {
            $result = fopen($https_url, 'r', false, $context); @fpassthru($result); @fclose($result);
        }
        elseif( $functionName=='file_get_contents' )
        {
            $result = file_get_contents($https_url, false, $context);
        }else{
            $result = curl_post($https_url, $method, $post_data, $cookies);
        }
        return $result;
    }

###########################################

    function curl_post( $https_url, $method='GET', $post_data='', $cookies='' ) 
    {
        $ch = curl_init();
        curl_setopt($ch, CURLOPT_URL,$https_url);
        curl_setopt($ch, CURLOPT_COOKIE, $cookies);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
        #curl_setopt($ch, CURLOPT_HEADER, 1);
        
        if( strtoupper($method) !='GET' )
        {
            curl_setopt($ch, CURLOPT_POST, 1);
            curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data);
        }

        curl_setopt($ch, CURLOPT_FAILONERROR, 1);
        $data = curl_exec($ch); if(!$data){ $data=curl_error($ch); }
        curl_close($ch);
        return $data;
    }
    
###########################################
    
    /*
        curl_fopen_getContents( $functionName, $method );
        
        $functionName = curl/fopen/file_get_contents
        $method       = GET/POST
    */
    echo curl_fopen_getContents( 'curl', 'GET' );
    
###########################################
?>

Can you help please? Thanks Alot.

问题是我忘记传递一些饼干..

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM