<small id='Y9Zu7'></small><noframes id='Y9Zu7'>

<legend id='Y9Zu7'><style id='Y9Zu7'><dir id='Y9Zu7'><q id='Y9Zu7'></q></dir></style></legend>
      <tfoot id='Y9Zu7'></tfoot>

        <i id='Y9Zu7'><tr id='Y9Zu7'><dt id='Y9Zu7'><q id='Y9Zu7'><span id='Y9Zu7'><b id='Y9Zu7'><form id='Y9Zu7'><ins id='Y9Zu7'></ins><ul id='Y9Zu7'></ul><sub id='Y9Zu7'></sub></form><legend id='Y9Zu7'></legend><bdo id='Y9Zu7'><pre id='Y9Zu7'><center id='Y9Zu7'></center></pre></bdo></b><th id='Y9Zu7'></th></span></q></dt></tr></i><div id='Y9Zu7'><tfoot id='Y9Zu7'></tfoot><dl id='Y9Zu7'><fieldset id='Y9Zu7'></fieldset></dl></div>

        • <bdo id='Y9Zu7'></bdo><ul id='Y9Zu7'></ul>
      1. 从 PHP cURL 响应中获取标头

        Get Header from PHP cURL response(从 PHP cURL 响应中获取标头)
            1. <i id='IDbq0'><tr id='IDbq0'><dt id='IDbq0'><q id='IDbq0'><span id='IDbq0'><b id='IDbq0'><form id='IDbq0'><ins id='IDbq0'></ins><ul id='IDbq0'></ul><sub id='IDbq0'></sub></form><legend id='IDbq0'></legend><bdo id='IDbq0'><pre id='IDbq0'><center id='IDbq0'></center></pre></bdo></b><th id='IDbq0'></th></span></q></dt></tr></i><div id='IDbq0'><tfoot id='IDbq0'></tfoot><dl id='IDbq0'><fieldset id='IDbq0'></fieldset></dl></div>
              • <bdo id='IDbq0'></bdo><ul id='IDbq0'></ul>

                1. <small id='IDbq0'></small><noframes id='IDbq0'>

                  <legend id='IDbq0'><style id='IDbq0'><dir id='IDbq0'><q id='IDbq0'></q></dir></style></legend>
                2. <tfoot id='IDbq0'></tfoot>

                    <tbody id='IDbq0'></tbody>

                  本文介绍了从 PHP cURL 响应中获取标头的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我是 PHP 新手.在发送 php curl POST 请求后,我试图从响应中获取 Header.客户端将请求发送到服务器,服务器将带有 Header 的响应发回.以下是我发送 POST 请求的方式.

                  I am new to PHP. I am trying to get the Header from the response after sending the php curl POST request. The client sends the request to the server and server sends back the response with Header. Here is how I sent my POST request.

                     $client = curl_init($url);  
                     curl_setopt($client, CURLOPT_CUSTOMREQUEST, "POST");
                     curl_setopt($client, CURLOPT_POSTFIELDS, $data_string);
                     curl_setopt($client, CURLOPT_HEADER, 1);
                     $response = curl_exec($client);
                     var_dump($response);
                  

                  这是我从浏览器获得的来自服务器的 Header 响应

                  Here is the Header response from server that I get from the browser

                  HTTP/1.1 200 OK 
                  Date: Wed, 01 Feb 2017 11:40:59 GMT 
                  Authorization: eyJhbGciOiJIUzI1NiJ9.eyJzdWIiOiJ1c2Vycy9CYW9CaW5oMTEwMiIsIm5hbWUiOiJhZG1pbiIsInBhc3N3b3JkIjoiMTIzNCJ9.kIGghbKQtMowjUZ6g62KirdfDUA_HtmW-wjqc3ROXjc Content-Type: text/html;charset=utf-8 Transfer-Encoding: chunked Server: Jetty(9.3.6.v20151106) 
                  

                  如何从 Header 中提取 Authorization 部分?我需要将其存储在 cookie 中

                  How can I extract the Authorization part from the Header ?. I need to store it in the cookies

                  推荐答案

                  它将所有的headers转换成一个数组

                  It converts all headers into an array

                  // create curl resource
                  $ch = curl_init();
                  
                  // set url
                  curl_setopt($ch, CURLOPT_URL, "example.com");
                  
                  //return the transfer as a string
                  curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
                  //enable headers
                  curl_setopt($ch, CURLOPT_HEADER, 1);
                  //get only headers
                  curl_setopt($ch, CURLOPT_NOBODY, 1);
                  // $output contains the output string
                  $output = curl_exec($ch);
                  
                  // close curl resource to free up system resources
                  curl_close($ch);
                  
                  $headers = [];
                  $output = rtrim($output);
                  $data = explode("
                  ",$output);
                  $headers['status'] = $data[0];
                  array_shift($data);
                  
                  foreach($data as $part){
                  
                      //some headers will contain ":" character (Location for example), and the part after ":" will be lost, Thanks to @Emanuele
                      $middle = explode(":",$part,2);
                  
                      //Supress warning message if $middle[1] does not exist, Thanks to @crayons
                      if ( !isset($middle[1]) ) { $middle[1] = null; }
                  
                      $headers[trim($middle[0])] = trim($middle[1]);
                  }
                  
                  // Print all headers as array
                  echo "<pre>";
                  print_r($headers);
                  echo "</pre>";
                  

                  这篇关于从 PHP cURL 响应中获取标头的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  DeepL的翻译效果还是很强大的,如果我们要用php实现DeepL翻译调用,该怎么办呢?以下是代码示例,希望能够帮到需要的朋友。 在这里需要注意,这个DeepL的账户和api申请比较难,不支持中国大陆申请,需要拥有香港或者海外信用卡才行,没账号的话,目前某宝可以
                  PHP通过phpspreadsheet导入Excel日期,导入系统后,全部变为了4开头的几位数字,这是为什么呢?原因很简单,将Excel的时间设置问文本,我们就能看到该日期本来的数值,上图对应的数值为: 要怎么解决呢?进行数据转换就行,这里可以封装方法,或者用第三方的
                  mediatemple - can#39;t send email using codeigniter(mediatemple - 无法使用 codeigniter 发送电子邮件)
                  Laravel Gmail Configuration Error(Laravel Gmail 配置错误)
                  Problem with using PHPMailer for SMTP(将 PHPMailer 用于 SMTP 的问题)
                  Issue on how to setup SMTP using PHPMailer in GoDaddy server(关于如何在 GoDaddy 服务器中使用 PHPMailer 设置 SMTP 的问题)

                    <legend id='DgtsF'><style id='DgtsF'><dir id='DgtsF'><q id='DgtsF'></q></dir></style></legend>
                      • <bdo id='DgtsF'></bdo><ul id='DgtsF'></ul>
                          <tbody id='DgtsF'></tbody>

                          <i id='DgtsF'><tr id='DgtsF'><dt id='DgtsF'><q id='DgtsF'><span id='DgtsF'><b id='DgtsF'><form id='DgtsF'><ins id='DgtsF'></ins><ul id='DgtsF'></ul><sub id='DgtsF'></sub></form><legend id='DgtsF'></legend><bdo id='DgtsF'><pre id='DgtsF'><center id='DgtsF'></center></pre></bdo></b><th id='DgtsF'></th></span></q></dt></tr></i><div id='DgtsF'><tfoot id='DgtsF'></tfoot><dl id='DgtsF'><fieldset id='DgtsF'></fieldset></dl></div>

                          <small id='DgtsF'></small><noframes id='DgtsF'>

                        1. <tfoot id='DgtsF'></tfoot>