コード例 #1
0
ファイル: HttpRequest.php プロジェクト: BionicClick/PHP-SDK
 public function request($content, $method = 'POST')
 {
     $this->resetResponse();
     if (Backendless::isBlMode()) {
         $this->setHeader("application-type", "BL");
     }
     if ($content !== 'null') {
         $this->request_headers['Content-length'] = strlen($content);
     }
     $headers = [];
     if (is_array($this->request_headers)) {
         $headers = array_map(function ($v, $k) {
             return sprintf("%s: %s", $k, $v);
         }, $this->request_headers, array_keys($this->request_headers));
     }
     $http = ['ignore_errors' => true, 'method' => $method, 'header' => implode("\r\n", $headers), 'timeout' => 10];
     if ($content !== 'null') {
         $http['content'] = $content;
     }
     $context = stream_context_create(['http' => $http, 'ssl' => ['verify_peer' => false, 'allow_self_signed' => false]]);
     $this->beforeRequest($http, $method);
     $this->response = file_get_contents($this->target_url, false, $context);
     $this->afterRequest();
     $this->response_headers = $http_response_header;
 }