public function ajaxAction() { $this->view = new Lupin_View(); $method = strtolower($this->_request->getParam('method')); $query_uri = trim($this->_request->getParam('query_uri'), '/ '); $url = $this->_request->getParam('url'); $extraParams = $this->_request->getParam('param'); $params = array('format' => $this->_request->getParam('format')); if (!empty($extraParams)) { foreach ($extraParams as $newParam) { $parms = explode('=', $newParam, 2); if (count($parms) > 1) { list($key, $value) = $parms; $params[$key] = $value; } } } $newMethod = HTTP_METH_GET; switch ($method) { case 'get': $newMethod = HTTP_METH_GET; break; case 'post': $newMethod = HTTP_METH_POST; break; case 'put': $newMethod = HTTP_METH_PUT; break; case 'delete': $newMethod = HTTP_METH_DELETE; break; case 'head': $newMethod = HTTP_METH_HEAD; break; } $email = $this->_request->getParam('email'); $pass = $this->_request->getParam('secretKey'); $request_url = 'http://' . $url . '/' . $query_uri; $request = new HttpRequest($request_url, $newMethod); if ($email && $pass) { $encoded_auth = base64_encode($email . ':' . $pass); $request->addHeaders(array('Authorization' => 'Basic ' . $encoded_auth)); } if ("post" == $method) { $request->addPostFields($params); } else { $request->addQueryData($params); } $res = $request->send(); function collapseHeaders($headers) { $header_string = ""; foreach ($headers as $name => $value) { $header_string .= $name . ": " . wordwrap($value, 45, "\n\t") . "\n"; } return $header_string; } $responseInfo = $request->getResponseInfo(); $response = array('request_url' => $responseInfo['effective_url'], 'response_headers' => collapseHeaders($res->getHeaders()), 'content' => $res->getBody(), 'status' => $res->getResponseCode(), 'method' => strtoupper($method), 'request_post_fields' => http_build_query(!is_null($postFields = $request->getPostFields()) ? $postFields : array())); $this->view->renderJson($response); }
public function ajaxAction() { $this->view = new Lupin_View(); $method = strtolower($this->_request->getParam('method')); $query_uri = trim($this->_request->getParam('query_uri'), '/ '); $url = $this->_request->getParam('url'); $ssl = $this->_request->getParam('ssl'); $extraParams = $this->_request->getParam('param'); $params = array(); if (!empty($extraParams)) { foreach ($extraParams as $newParam) { $parms = explode('=', $newParam, 2); if (count($parms) > 1) { list($key, $value) = $parms; $params[$key] = $value; } } } $newMethod = HTTP_METH_GET; switch ($method) { case 'get': $newMethod = HTTP_METH_GET; break; case 'post': $newMethod = HTTP_METH_POST; break; case 'put': $newMethod = HTTP_METH_PUT; break; case 'delete': $newMethod = HTTP_METH_DELETE; break; case 'head': $newMethod = HTTP_METH_HEAD; break; } $email = $this->_request->getParam('email'); $pass = $this->_request->getParam('secretKey'); $request_url = 'http' . ($ssl !== null ? 's' : '') . '://' . $url . '/' . $query_uri; $httpOptions = array(); if ($email && $pass) { $httpOptions = array('headers' => array('Accept' => '*/*'), 'httpauth' => $email . ':' . $pass, 'httpauthtype' => HTTP_AUTH_DIGEST); } $request = new HttpRequest($request_url, $newMethod, $httpOptions); if ("post" == $method) { $request->addPostFields($params); } else { $request->addQueryData($params); } $res = $request->send(); $responseInfo = $request->getResponseInfo(); $response = array('request_url' => $responseInfo['effective_url'], 'response_headers' => $this->collapseHeaders($res->getHeaders()), 'content' => $res->getBody(), 'status' => $res->getResponseCode(), 'method' => strtoupper($method), 'request_post_fields' => http_build_query(!is_null($postFields = $request->getPostFields()) ? $postFields : array())); $this->view->renderJson($response); }
/** * Signs request with signature version 2 * * Only POST http method is supported * * @param \HttpRequest $request Http request object * @throws QueryClientException */ protected function signRequestV2($request) { $time = time(); //Gets the http method name $httpMethod = self::$httpMethods[$request->getMethod()]; //Gets both host and path from the url $components = parse_url($request->getUrl()); $common = ['AWSAccessKeyId' => $this->awsAccessKeyId, 'SignatureVersion' => '2', 'SignatureMethod' => 'HmacSHA1', 'Timestamp' => gmdate('Y-m-d\\TH:i:s', $time) . "Z"]; $request->addPostFields($common); //Gets adjusted options $options = $request->getPostFields(); //Calculating canonicalized query string ksort($options); $canonicalizedQueryString = ''; foreach ($options as $k => $v) { $canonicalizedQueryString .= '&' . rawurlencode($k) . '=' . rawurlencode($v); } $canonicalizedQueryString = ltrim($canonicalizedQueryString, '&'); $stringToSign = $httpMethod . "\n" . strtolower($components['host']) . "\n" . $components['path'] . "\n" . $canonicalizedQueryString; switch ($common['SignatureMethod']) { case 'HmacSHA1': case 'HmacSHA256': $algo = strtolower(substr($common['SignatureMethod'], 4)); break; default: throw new QueryClientException('Unknown SignatureMethod ' . $common['SignatureMethod']); } $request->addPostFields(['Signature' => base64_encode(hash_hmac($algo, $stringToSign, $this->secretAccessKey, 1))]); $request->addHeaders(['X-Amz-Date' => gmdate(\DateTime::ISO8601, $time)]); }
<?php var_dump(HttpRequest::getPostFields()); die;