奇怪的curl 403错误

最近在一家公司实习,按照他们技术总裁的要求写一个URL连接检查器,从数据库里面select出url后判断他的访问状态生成报告,php或者python任选,我自然选择了自己最熟悉的php了

但是程序跑了一遍以后发现几个问题,首先是1w3k 条记录下用foreach去循环每个数组中的URL,效率太低下,只有几个数据还好,1w3k算不上海量,但是也不少了,设置curl超时时间为3秒还是时间太长,完整的跑一次要一个上午,这个还不是最恼人的,关键是好奇怪的误报问题,明明浏览器下面可以访问,为什么他取回的就是http 403呢?

考虑Useragent过滤,没错,确实有这个问题,但是是少数,仔细思考无奈只能求职Google

SEE:http://forums.devshed.com/php-development-5/trouble-with-a-curl-request-in-php-445222.html

为了加快速度,我设置了不读取body

这样的话,如果http服务器不允许 HEAD 命令,就会返回403错误。
解决办法:使用GET

Author Info : From:奇怪的curl 403错误 URL:http://blog.ihipop.info/2010/07/1327.html Please Reserve This Link,Thanks!
发布了430 篇原创文章 · 获赞 415 · 访问量 925万+
展开阅读全文

403 Forbidden - 该页面需要客户端证书作为身份验证过程的一部分

04-25

<div class="post-text" itemprop="text"> <p>I am in the process of implementing a SOAP client in PHP. I have received a <code>.pfx</code> certificate from the remote company implementing the SOAP service.</p> <p>When I import this <code>.pfx</code> in Chrome and open the WDSL file at: <code>https://api.test.remote.company.com/O/OMS.svc?singlewsdl</code>, I get an XML file indeed.</p> <p>Since I need to use <code>.pem</code> certificates for PHP's <code>SoapClient</code>, I have converted the <code>.pfx</code> with the following:</p> <pre><code>openssl pkcs12 -in received.pfx -out converted.pem -clcerts </code></pre> <p>Since I was still facing issues with my client, I resorted to perform a test with Curl:</p> <pre><code>curl --verbose --cert converted.pem:MyPassphrase https://api.test.remote.company.com/O/OMS.svc?singlewsdl </code></pre> <p>But I get a 403 error message:</p> <pre><code>* Trying 123.4.56.789... * Connected to api.test.remote.company.com (123.4.56.789) port 443 (#0) * found 173 certificates in /etc/ssl/certs/ca-certificates.crt * found 697 certificates in /etc/ssl/certs * ALPN, offering http/1.1 * SSL connection using TLS1.2 / ECDHE_RSA_AES_256_CBC_SHA384 * server certificate verification OK * server certificate status verification SKIPPED * common name: test.api.company.com (matched) * server certificate expiration date OK * server certificate activation date OK * certificate public key: RSA * certificate version: #3 * subject: C=RU,ST=Moscow,L=Moscow,O=AO Company Lab,OU=IT,CN=test.api.company.com * start date: Tue, 31 May 2016 00:00:00 GMT * expire date: Thu, 08 Jun 2017 23:59:59 GMT * issuer: C=US,O=thawte\, Inc.,CN=thawte SSL CA - G2 * compression: NULL * ALPN, server did not agree to a protocol > GET /O/OMS.svc?singlewsdl HTTP/1.1 > Host: api.test.remote.company.com > User-Agent: curl/7.50.1 > Accept: */* > < HTTP/1.1 403 Forbidden ( The page requires a client certificate as part of the authentication process. If you are using a smart card, you will need to insert your smart card to select an appropriate certificate. Otherwise, contact your server administrator. ) < Connection: close < Pragma: no-cache < Cache-Control: no-cache < Content-Type: text/html ... </code></pre> <p>Does anyone know what is happening and how it can be solved?</p> </div> 问答

PHP cURL Put,没有权限(403禁止)

01-04

<div class="post-text" itemprop="text"> <p>I made a script that uses the Mobile.de API. It worked fine on their test environment, only difference with the live environment is the proxy. So in my cURL I removed the proxy. For any POST call this works just fine, but for my PUT call it doesn't work at all.</p> <p>So let's say I sent the following with for example Postman:</p> <blockquote> <p>PUT /seller-api/sellers/123/ads/456<br> Host: services.mobile.de <br> Content-Type: application/vnd.de.mobile.api+json <br> Authorization: Basic abcdef12345=</p> </blockquote> <p>And I put in the right JSON, it works just fine. <br> And this is the script I use in PHP:</p> <pre><code>function updateVehicle($seller, $voertuig_id, $json) { $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, 'https://services.mobile.de/seller-api/sellers/' . $seller . '/ads/' . $voertuig_id); curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "PUT"); curl_setopt($ch, CURLOPT_POSTFIELDS, $json); curl_setopt($ch, CURLINFO_HEADER_OUT, true); curl_setopt($ch, CURLOPT_USERPWD, USERNAME . ':' . PASSWORD); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_HEADER, 1); curl_setopt($ch, CURLOPT_HTTPHEADER, array( 'Host: services.mobile.de', 'Content-type: application/vnd.de.mobile.api+json' )); $output = curl_exec($ch); curl_close($ch); return $output; } </code></pre> <p>In return I get the 403 forbidden. 'You don't have permission to access /seller-api/sellers/123/ads/456 on this server.'</p> <p>I already printed out al curl info and saw that all the headers are there and everything seems just fine, but why don't I have permission.</p> <p>Contacted Mobile.de already but they say it's something in my code.</p> </div> 问答

Laravel卷曲请求导致了“403 Forbidden”响应

08-09

<div class="post-text" itemprop="text"> <p>I am working on a laravel based project and I need to import time entries from Toggl account. Toggl seems to have correct API in place but I am not able to pull records via API for some reason. </p> <p>I am using the below-mentioned library to access Toggl API. <a href="https://medium.com/laravel-5-the-right-way/using-guzzlehttp-with-laravel-1dbea1f633da" rel="nofollow noreferrer">https://medium.com/laravel-5-the-right-way/using-guzzlehttp-with-laravel-1dbea1f633da</a></p> <p>I am getting below error on every request to API. GuzzleHttp \ Exception \ ClientException (403) Client error: <code>GET https://toggl.com/api/v8/time_entries?user_agent=deepak%40gmail.com&workspace_id=257895&with_related_data=1</code> resulted in a <code>403 Forbidden</code> response</p> <p>I have tried to fix it by adding or removing (below-mentioned) header elements that are sent with each request. But it still does not work. </p> <pre class="lang-php prettyprint-override"><code>use GuzzleHttp\Exception\GuzzleException; use GuzzleHttp\Client; $client = new Client; $credentials = base64_encode('e5e8238ca0fee3ca726e486733c87456:api_token'); $url = 'https://toggl.com/api/v8/time_entries'; $response = $client->get($url, [ 'referer' => true, 'headers' => [ 'Authorization: Basic ' => $credentials, 'Content-Type: application/json', 'User-Agent' => 'Mozilla /5.0 (Compatible MSIE 9.0;Windows NT 6.1;WOW64; Trident/5.0)', 'Accept' => 'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8', 'Accept-Encoding' => 'gzip, deflate, br', ], 'query' => [ 'user_agent' => 'deepak@gmail.com', 'workspace_id' => '8756952', 'with_related_data' => true, ], "http_errors" => false, ]); dd($response); </code></pre> <p>It should retrieve the records from Toggl and print a JSON on the browser. </p> <p>Interestingly, I am able to pull records through the command-line interface using the command below. curl -v -u e5e8238ca0fee3ca726e486733c85468:api_token -X GET <a href="https://www.toggl.com/api/v8/time_entries" rel="nofollow noreferrer">https://www.toggl.com/api/v8/time_entries</a></p> <p>Please know that in the above code snippet, I have changed the API key for obvious reasons.</p> <p>Thanks</p> </div> 问答

没有更多推荐了,返回首页

©️2019 CSDN 皮肤主题: 编程工作室 设计师: CSDN官方博客

分享到微信朋友圈

×

扫一扫,手机浏览