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

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

    • <bdo id='uJoIo'></bdo><ul id='uJoIo'></ul>

      <legend id='uJoIo'><style id='uJoIo'><dir id='uJoIo'><q id='uJoIo'></q></dir></style></legend>

      1. 如何从 CURL 响应中删除 HTTP 标头?

        How to remove HTTP headers from CURL response?(如何从 CURL 响应中删除 HTTP 标头?)
          <tbody id='N1f9g'></tbody>
        <tfoot id='N1f9g'></tfoot>
        1. <i id='N1f9g'><tr id='N1f9g'><dt id='N1f9g'><q id='N1f9g'><span id='N1f9g'><b id='N1f9g'><form id='N1f9g'><ins id='N1f9g'></ins><ul id='N1f9g'></ul><sub id='N1f9g'></sub></form><legend id='N1f9g'></legend><bdo id='N1f9g'><pre id='N1f9g'><center id='N1f9g'></center></pre></bdo></b><th id='N1f9g'></th></span></q></dt></tr></i><div id='N1f9g'><tfoot id='N1f9g'></tfoot><dl id='N1f9g'><fieldset id='N1f9g'></fieldset></dl></div>
          • <bdo id='N1f9g'></bdo><ul id='N1f9g'></ul>

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

                  <legend id='N1f9g'><style id='N1f9g'><dir id='N1f9g'><q id='N1f9g'></q></dir></style></legend>
                  本文介绍了如何从 CURL 响应中删除 HTTP 标头?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我有一个 php 脚本,它只返回纯文本没有任何 html.现在我想对该脚本发出一个 cURL 请求,我得到以下响应:

                  I have a php script that returns just plain text without any html. Now I want to make a cURL request to that script and I get the following response:

                  HTTP/1.1 200 OK
                  Date: Mon, 28 Feb 2011 14:21:51 GMT
                  Server: Apache/2.2.14 (Ubuntu)
                  X-Powered-By: PHP/5.2.12-nmm2
                  Vary: Accept-Encoding
                  Content-Length: 6
                  Content-Type: text/html
                  
                  6.8320
                  

                  实际响应只是 6.8320 作为没有任何 html 的文本.我想通过删除标题信息从上面的响应中检索它.

                  The actuall response is just 6.8320 as text without any html. I want to retrieve it from the response above by just removing the header information.

                  我已经把脚本缩小了一点:

                  I already minified the script a bit:

                  $url = $_GET['url'];
                  
                  if ( !$url ) {
                  
                    // Passed url not specified.
                    $contents = 'ERROR: url not specified';
                    $status = array( 'http_code' => 'ERROR' );
                  
                  } else if ( !preg_match( $valid_url_regex, $url ) ) {
                  
                    // Passed url doesn't match $valid_url_regex.
                    $contents = 'ERROR: invalid url';
                    $status = array( 'http_code' => 'ERROR' );
                  
                  } else {
                    $ch = curl_init( $url );
                  
                    if ( strtolower($_SERVER['REQUEST_METHOD']) == 'post' ) {
                      curl_setopt( $ch, CURLOPT_POST, true );
                      curl_setopt( $ch, CURLOPT_POSTFIELDS, $_POST );
                    }
                  
                    curl_setopt( $ch, CURLOPT_FOLLOWLOCATION, true );
                    curl_setopt( $ch, CURLOPT_HEADER, true );
                    curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true );
                  
                    curl_setopt( $ch, CURLOPT_USERAGENT, $_GET['user_agent'] ? $_GET['user_agent'] : $_SERVER['HTTP_USER_AGENT'] );
                  
                    list( $header, $contents ) = preg_split( '/([
                  ][
                  ])\1/', curl_exec( $ch ), 2 );
                  
                    $status = curl_getinfo( $ch );
                  
                    curl_close( $ch );
                  }
                  
                  // Split header text into an array.
                  $header_text = preg_split( '/[
                  ]+/', $header );
                  
                  if ( true ) {
                    if ( !$enable_native ) {
                      $contents = 'ERROR: invalid mode';
                      $status = array( 'http_code' => 'ERROR' );
                    }
                  
                    // Propagate headers to response.
                    foreach ( $header_text as $header ) {
                      if ( preg_match( '/^(?:Content-Type|Content-Language|Set-Cookie):/i', $header ) ) {
                        header( $header );
                      }
                    }
                    print $contents;
                  }
                  

                  知道我需要更改什么来从响应中删除标头信息吗?

                  Any idea what I need to change to remove the header information from the response?

                  推荐答案

                  只需将 CURLOPT_HEADER 设置为 false.

                  Just set CURLOPT_HEADER to false.

                  这篇关于如何从 CURL 响应中删除 HTTP 标头?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

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

                  相关文档推荐

                  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 的问题)
                  smtp gmail server php mailer not working(smtp gmail服务器php邮件程序不工作)
                  Email goes in spam when I send it via others SMTP server(当我通过其他 SMTP 服务器发送电子邮件时,电子邮件进入垃圾邮件)
                    <tbody id='EvOpm'></tbody>

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

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

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