cURL not returning anything?

前端 未结 4 1271
Happy的楠姐
Happy的楠姐 2020-12-10 08:56
 \"http://domain.com\",
    \"loginCheck\"     => \"checkuser.php\",
    \"userAgent\"         


        
4条回答
  •  粉色の甜心
    2020-12-10 09:15

    You can use a class that I wrote that wraps around CURL. To install, see: https://github.com/homer6/altumo

    It's much easier to use and can give you some easy to access debugging. For example:

    try{
    
        //load class autoloader
            require_once( __DIR__ . '/loader.php' );  //you should ensure that is is the correct path for this file
    
        //make the response; return the response with the headers
            $client = new \Altumo\Http\OutgoingHttpRequest( 'http://www.domain.com/checkuser.php', array(
                'username' => 'user',
                'password' => 'pass',
                'submit' => ' Login '
            ));
            $client->setRequestMethod( \Altumo\Http\OutgoingHttpRequest::HTTP_METHOD_POST );
    
        //send the request (with optional arguments for debugging)           
            //the first true will return the response headers
            //the second true will turn on curl info so that it can be retrieved later
            $response = $client->send( true, true );
    
        //output the response and curl info
            \Altumo\Utils\Debug::dump( $response, $client->getCurlInfo() );
    
        //alternatively, you can get the response wrapped in an object that allows you to retrieve parts of the response
            $http_response =  $client->sendAndGetResponseMessage( true );
            $status_code = $http_response->getStatusCode();
            $message_body = $http_response->getMessageBody();
            $full_http_response = $http_response->getRawHttpResponse();
            \Altumo\Utils\Debug::dump( $status_code, $message_body, $full_http_response );
    
    
    }catch( \Exception $e ){
    
        //This will display an error if any exceptions have been thrown
        echo 'Error: ' . $e->getMessage();
    
    }
    

    Hope that helps...

提交回复
热议问题