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

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

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

      • <bdo id='KllQL'></bdo><ul id='KllQL'></ul>
      <i id='KllQL'><tr id='KllQL'><dt id='KllQL'><q id='KllQL'><span id='KllQL'><b id='KllQL'><form id='KllQL'><ins id='KllQL'></ins><ul id='KllQL'></ul><sub id='KllQL'></sub></form><legend id='KllQL'></legend><bdo id='KllQL'><pre id='KllQL'><center id='KllQL'></center></pre></bdo></b><th id='KllQL'></th></span></q></dt></tr></i><div id='KllQL'><tfoot id='KllQL'></tfoot><dl id='KllQL'><fieldset id='KllQL'></fieldset></dl></div>
    1. 在标头php curl中发送身份验证

      Sending auth in headers php curl(在标头php curl中发送身份验证)
      <i id='TyEmV'><tr id='TyEmV'><dt id='TyEmV'><q id='TyEmV'><span id='TyEmV'><b id='TyEmV'><form id='TyEmV'><ins id='TyEmV'></ins><ul id='TyEmV'></ul><sub id='TyEmV'></sub></form><legend id='TyEmV'></legend><bdo id='TyEmV'><pre id='TyEmV'><center id='TyEmV'></center></pre></bdo></b><th id='TyEmV'></th></span></q></dt></tr></i><div id='TyEmV'><tfoot id='TyEmV'></tfoot><dl id='TyEmV'><fieldset id='TyEmV'></fieldset></dl></div>
            <tbody id='TyEmV'></tbody>

            • <bdo id='TyEmV'></bdo><ul id='TyEmV'></ul>
            • <small id='TyEmV'></small><noframes id='TyEmV'>

              <tfoot id='TyEmV'></tfoot>
              <legend id='TyEmV'><style id='TyEmV'><dir id='TyEmV'><q id='TyEmV'></q></dir></style></legend>
              • 本文介绍了在标头php curl中发送身份验证的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                问题描述

                尝试在 PHP 中做同样的事情 - 但失败了:):

                trying to do the equivalent of this in PHP - and failing :):

                curl -H "X-abc-AUTH: 123456789" http://APIserviceProvider=http://www.cnn.com;
                

                123456789"是 API 密钥.命令行语句工作正常.

                "123456789" is the API key. The command line statement works fine.

                PHP 代码(不起作用):

                PHP code (does not work):

                $urlToGet = "http://www.cnn.com";
                $service_url = "http://APIserviceProvider=$urlToGet";
                
                //header
                
                 $contentType = 'text/xml';          //probably not needed
                 $method = 'POST';                   //probably not needed
                 $auth = 'X-abc-AUTH: 123456789';    //API Key
                
                $ch = curl_init();
                curl_setopt($ch, CURLOPT_URL, $service_url);
                curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
                curl_setopt($ch, CURLINFO_HEADER_OUT, true);
                
                //does not work
                
                
                
                // curl_setopt($ch, CURLOPT_HTTPHEADER, Array('Content-type: ' . 
                   // $contentType . '; auth=' . $auth));
                
                    //works!   (THANKS @Fratyr for the clue):
                
                    curl_setopt($ch, CURLOPT_HTTPHEADER, Array($auth));
                
                //this works too (THANKS @sergiocruz):
                
                curl_setopt($ch, CURLOPT_HTTPHEADER, array(
                  'Some_custom_header: 0',
                  'Another_custom_header: 143444,12'
                ));
                
                
                //exec
                
                $data = curl_exec($ch);
                echo $data;
                curl_close($ch);
                

                有什么想法吗?

                推荐答案

                为了将自定义标题添加到您的 curl 中,您应该执行以下操作:

                In order to get custom headers into your curl you should do something like the following:

                curl_setopt($ch, CURLOPT_HTTPHEADER, array(
                  'Some_custom_header: 0',
                  'Another_custom_header: 143444,12'
                ));
                

                因此,以下内容应该适用于您的情况(假设 X-abc-AUTH 是您需要发送的唯一标头):

                Therefore the following should work in your case (given X-abc-AUTH is the only header you need to send over):

                curl_setopt($ch, CURLOPT_HTTPHEADER, array(
                  'X-abc-AUTH: 123456789' // you can replace this with your $auth variable
                ));
                

                如果您需要额外的自定义标头,您所要做的就是添加到 curl_setopt 内的数组中.

                If you need additional custom headers, all you have to do is add on to the array within the curl_setopt.

                我希望这会有所帮助:)

                I hope this helps :)

                这篇关于在标头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='WNbxV'><style id='WNbxV'><dir id='WNbxV'><q id='WNbxV'></q></dir></style></legend>
                  <bdo id='WNbxV'></bdo><ul id='WNbxV'></ul>

                    <tfoot id='WNbxV'></tfoot>
                      <tbody id='WNbxV'></tbody>
                    <i id='WNbxV'><tr id='WNbxV'><dt id='WNbxV'><q id='WNbxV'><span id='WNbxV'><b id='WNbxV'><form id='WNbxV'><ins id='WNbxV'></ins><ul id='WNbxV'></ul><sub id='WNbxV'></sub></form><legend id='WNbxV'></legend><bdo id='WNbxV'><pre id='WNbxV'><center id='WNbxV'></center></pre></bdo></b><th id='WNbxV'></th></span></q></dt></tr></i><div id='WNbxV'><tfoot id='WNbxV'></tfoot><dl id='WNbxV'><fieldset id='WNbxV'></fieldset></dl></div>
                    1. <small id='WNbxV'></small><noframes id='WNbxV'>