EAuthServiceBase::initRequest PHP Method

initRequest() protected method

Initializes a new session and return a cURL handle.
protected initRequest ( string $url, array $options = [] ) : cURL
$url string url to request.
$options array HTTP request options. Keys: query, data, referer.
return cURL handle.
    protected function initRequest($url, $options = array())
    {
        $ch = curl_init();
        //curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1); // error with open_basedir or safe mode
        curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 0);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
        curl_setopt($ch, CURLOPT_HEADER, 0);
        curl_setopt($ch, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_0);
        if (isset($options['referer'])) {
            curl_setopt($ch, CURLOPT_REFERER, $options['referer']);
        }
        if (isset($options['headers'])) {
            curl_setopt($ch, CURLOPT_HTTPHEADER, $options['headers']);
        }
        if (isset($options['query'])) {
            $url_parts = parse_url($url);
            if (isset($url_parts['query'])) {
                $query = $url_parts['query'];
                if (strlen($query) > 0) {
                    $query .= '&';
                }
                $query .= http_build_query($options['query']);
                $url = str_replace($url_parts['query'], $query, $url);
            } else {
                $url_parts['query'] = $options['query'];
                $new_query = http_build_query($url_parts['query']);
                $url .= '?' . $new_query;
            }
        }
        if (isset($options['data'])) {
            curl_setopt($ch, CURLOPT_POST, 1);
            curl_setopt($ch, CURLOPT_POSTFIELDS, $options['data']);
        }
        curl_setopt($ch, CURLOPT_URL, $url);
        return $ch;
    }

Usage Example

Example #1
0
 /**
  * Initializes a new session and return a cURL handle.
  * @param string $url url to request.
  * @param array $options HTTP request options. Keys: query, data, referer.
  * @param boolean $parseJson Whether to parse response in json format.
  * @return cURL handle.
  */
 protected function initRequest($url, $options = array())
 {
     $ch = parent::initRequest($url, $options);
     curl_setopt($ch, CURLOPT_HTTPHEADER, array('Expect:'));
     if (isset($params['data'])) {
         curl_setopt($ch, CURLOPT_HTTPHEADER, array("Content-Type: text/xml", "SOAPAction: \"/soap/action/query\"", "Content-length: " . strlen($data)));
     }
     return $ch;
 }
All Usage Examples Of EAuthServiceBase::initRequest