SEOstats/Helper/HttpRequest.php
/**
     *  HTTP GET/POST request with curl.
     *  @access    public
     *  @param     String      $url        The Request URL
     *  @param     Array       $postData   Optional: POST data array to be send.
     *  @return    Mixed                   On success, returns the response string.
     *                                     Else, the the HTTP status code received
     *                                     in reponse to the request.
     */
HTTP GET/POST request with curl.
@access    public
@param     String      $url        The Request URL
@param     Array       $postData   Optional: POST data array to be send.
@return    Mixed                   On success, returns the response string.
Else, the the HTTP status code received
in reponse to the request.
HTTP GET / POST request with curl . @access public @param String $url The Request URL @param Array $postData Optional : POST data array to be send . @return Mixed On success returns the response string . Else the the HTTP status code received in reponse to the request .
public static function sendRequest($url, $postData = false, $postJson = false)
    {
        $ua = self::getUserAgent();
        $curlopt_proxy = self::getProxy();
        $curlopt_proxyuserpwd = self::getProxyUserPwd();
        $ch = curl_init($url);
        curl_setopt_array($ch, array(
            CURLOPT_USERAGENT       => $ua,
            CURLOPT_RETURNTRANSFER  => 1,
            CURLOPT_CONNECTTIMEOUT  => 30,
            CURLOPT_FOLLOWLOCATION  => 1,
            CURLOPT_MAXREDIRS       => 2,
            CURLOPT_SSL_VERIFYPEER  => 0,
        ));
        if($curlopt_proxy) {
            curl_setopt($ch, CURLOPT_PROXY, $curlopt_proxy);
        }
        if($curlopt_proxyuserpwd) {
            curl_setopt($ch, CURLOPT_PROXYUSERPWD, $curlopt_proxyuserpwd);
        }
        if (false !== $postData) {
            if (false !== $postJson) {
                curl_setopt($ch, CURLOPT_HTTPHEADER,
                    array('Content-type: application/json'));
                $data = json_encode($postData);
            } else {
                $data = http_build_query($postData);
            }
            curl_setopt($ch, CURLOPT_POST, 1);
            curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
        }
        $response = curl_exec($ch);
        $httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
        curl_close($ch);
        return (200 == (int)$httpCode) ? $response : false;
    }
public static function sendRequest ( $ url , $ postData = false , $ postJson = false ) { $ ua = self :: getUserAgent ( ) ; $ curlopt_proxy = self :: getProxy ( ) ; $ curlopt_proxyuserpwd = self :: getProxyUserPwd ( ) ; $ ch = curl_init ( $ url ) ; curl_setopt_array ( $ ch , array ( CURLOPT_USERAGENT => $ ua , CURLOPT_RETURNTRANSFER => 1 , CURLOPT_CONNECTTIMEOUT => 30 , CURLOPT_FOLLOWLOCATION => 1 , CURLOPT_MAXREDIRS => 2 , CURLOPT_SSL_VERIFYPEER => 0 , ) ) ; if ( $ curlopt_proxy ) { curl_setopt ( $ ch , CURLOPT_PROXY , $ curlopt_proxy ) ; } if ( $ curlopt_proxyuserpwd ) { curl_setopt ( $ ch , CURLOPT_PROXYUSERPWD , $ curlopt_proxyuserpwd ) ; } if ( false !== $ postData ) { if ( false !== $ postJson ) { curl_setopt ( $ ch , CURLOPT_HTTPHEADER , array ( 'Content-type: application/json' ) ) ; $ data = json_encode ( $ postData ) ; } else { $ data = http_build_query ( $ postData ) ; } curl_setopt ( $ ch , CURLOPT_POST , 1 ) ; curl_setopt ( $ ch , CURLOPT_POSTFIELDS , $ data ) ; } $ response = curl_exec ( $ ch ) ; $ httpCode = curl_getinfo ( $ ch , CURLINFO_HTTP_CODE ) ; curl_close ( $ ch ) ; return ( 200 == ( int ) $ httpCode ) ? $ response : false ; }
HTTP GET/POST request with curl.
HTTP GET / POST request with curl .