Curl 403 ошибка

I am trying to duplicate the Http headers in Php Curl.

My http header is below

Host: plus.google.com

Content-Type: application/x-www-form-urlencoded; 

Cookie:NID=67=pdjIQN5CUKVn0bRgAlqitBk7WHVivLsbLcr7QOWMn35Pq03N1WMy6kxYBPORtaQUPQrfMK4Yo0vVz8tH97ejX3q7P2lNuPjTOhwqaI2bXCgPGSDKkdFoiYIqXubR0cTJ48hIAaKQqiQi_lpoe6edhMglvOO9ynw; PREF=ID=52aa671013493765:U=0cfb5c96530d04e3:FF=0:LD=en:TM=1370266105:LM=1370341612:GM=1:S=Kcc6KUnZwWfy3cOl; OTZ=1800625_34_34__34_; S=talkgadget=38GaRzFbruDPtFjrghEtRw; SID=DQAAALoAAADHyIbtG3J_u2hwNi4N6UQWgXlwOAQL58VRB_0xQYbDiL2HA5zvefboor5YVmHc8Zt5lcA0LCd2Riv4WsW53ZbNCv8Qu_THhIvtRgdEZfgk26LrKmObye1wU62jESQoNdbapFAfEH_IGHSIA0ZKsZrHiWLGVpujKyUvHHGsZc_XZm4Z4tb2bbYWWYAv02mw2njnf4jiKP2QTxnlnKFK77UvWn4FFcahe-XTk8Jlqblu66AlkTGMZpU0BDlYMValdnU; HSID=A6VT_ZJ0ZSm8NTdFf; SSID=A9_PWUXbZLazoEskE; APISID=RSS_BK5QSEmzBxlS/ApSt2fMy1g36vrYvk; SAPISID=xxxxxxxxxxxxxx

Now in firexfox http header addon, when i press replay this works correct.But when i do the same via php cur using below code i get error

<?php

function poster($url,$fields_string){
        $ch = curl_init();
        //set the url, number of POST vars, POST data
        curl_setopt($ch,CURLOPT_URL, $url);

        curl_setopt($ch, CURLOPT_HEADER, true);
        curl_setopt($ch, CURLOPT_HTTPHEADERS,array('Content-Type:application/x-www-form-urlencoded','Cookie: NID=67=pdjIQN5CUKVn0bRgAlqitBk7WHVivLsbLcr7QOWMn35Pq03N1WMy6kxYBPORtaQUPQrfMK4Yo0vVz8tH97ejX3q7P2lNuPjTOhwqaI2bXCgPGSDKkdFoiYIqXubR0cTJ48hIAaKQqiQi_lpoe6edhMglvOO9ynw; PREF=ID=52aa671013493765:U=0cfb5c96530d04e3:FF=0:LD=en:TM=1370266105:LM=1370341612:GM=1:S=Kcc6KUnZwWfy3cOl; OTZ=1800625_34_34__34_; S=talkgadget=38GaRzFbruDPtFjrghEtRw; SID=DQAAALoAAADHyIbtG3J_u2hwNi4N6UQWgXlwOAQL58VRB_0xQYbDiL2HA5zvefboor5YVmHc8Zt5lcA0LCd2Riv4WsW53ZbNCv8Qu_THhIvtRgdEZfgk26LrKmObye1wU62jESQoNdbapFAfEH_IGHSIA0ZKsZrHiWLGVpujKyUvHHGsZc_XZm4Z4tb2bbYWWYAv02mw2njnf4jiKP2QTxnlnKFK77UvWn4FFcahe-XTk8Jlqblu66AlkTGMZpU0BDlYMValdnU; HSID=A6VT_ZJ0ZSm8NTdFf; SSID=A9_PWUXbZLazoEskE; APISID=RSS_BK5QSEmzBxlS/ApSt2fMy1g36vrYvk; SAPISID=ZIMOP9lJ_E8SLdkL/A32W20hPpwgd5Kg1J'));

        curl_setopt($ch, CURLOPT_RETURNTRANSFER,true);
        curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US) AppleWebKit/525.13 (KHTML, like Gecko) Chrome/0.A.B.C Safari/525.13");
        curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
        curl_setopt($ch, CURLOPT_MAXREDIRS, 20); 
        curl_setopt($ch,CURLOPT_POST, count($fields_string));
        curl_setopt($ch,CURLOPT_POSTFIELDS, $fields_string);
        $result = curl_exec($ch);
        $last = curl_getinfo($ch, CURLINFO_EFFECTIVE_URL);
        return array($result,$last);
        curl_close($ch);
    }



    $url = "https://plus.google.com/_/sharebox/post/?source=frameless&spam=56&hl=en&ozv=es_oz_20130602.13_p3&f.sid=-834406139015290241&_reqid=358119&rt=j";
    $string = 'f.req=%5B%22%22%2C%22oz%3A105057244581488239720.13f0ec465f5.0%22%2Cnull%2Cnull%2Cnull%2Cnull%2C%22%5B%5D%22%2Cnull%2Cnull%2Ctrue%2C%5B%5D%2Cfalse%2Cnull%2Cnull%2C%5B%5D%2Cnull%2Cfalse%2Cnull%2Cnull%2Cnull%2Cnull%2Cnull%2Cnull%2Cnull%2Cnull%2Cnull%2Cnull%2Cfalse%2Cfalse%2Cfalse%2Cnull%2Cnull%2Cnull%2Cnull%2C%5B%5B337%2C336%2C335%2C0%5D%2C%22http%3A%2F%2Fadjmpw.com%22%2Cnull%2Cnull%2Cnull%2Cnull%2C%7B%2240154698%22%3A%5B%22http%3A%2F%2Fadjmpw.com%22%2Cnull%2C%22DOMAIN%20ERROR%22%2C%22%5Cu30c9%5Cu30e1%5Cu30a4%5Cu30f3%5Cu30a6%5Cu30a7%5Cu30d6%5Cu306e%5Cu8a2d%5Cu5b9a%5Cu304c%5Cu898b%5Cu3064%5Cu304b%5Cu308a%5Cu307e%5Cu305b%5Cu3093.%20%5Cu8003%5Cu3048%5Cu3089%5Cu308c%5Cu308b%5Cu539f%5Cu56e0.%20%5Cu30c9%5Cu30e1%5Cu30a4%5Cu30f3%5Cu30a6%5Cu30a7%5Cu30d6%5Cu306e%5Cu8a2d%5Cu5b9a%5Cu304c%5Cu307e%5Cu3060%5Cu884c%5Cu308f%5Cu308c%5Cu3066%5Cu3044%5Cu306a%5Cu3044%5Cu3002%20%5Cu30c9%5Cu30e1%5Cu30a4%5Cu30f3%5Cu30a6%5Cu30a7%5Cu30d6%5Cu306e%5Cu8a2d%5Cu5b9a%5Cu304c%5Cu307e%5Cu3060%5Cu53cd%5Cu6620%5Cu3055%5Cu308c%5Cu3066%5Cu3044%5Cu306a%5Cu3044%5Cu3002(%5Cu53cd%5Cu6620%5Cu306b%5Cu306f%5Cu6570%5Cu6642%5Cu9593%5Cuff5e24%5Cu6642%5Cu9593%5Cu304b%5Cu304b%5Cu308b%5Cu3053%5Cu3068%5Cu304c%5Cu3042%5Cu308a%5Cu307e%5Cu3059)%3B%20%5Cu30c9%5Cu30e1%5Cu30a4%5Cu30f3%5Cu30a6%5Cu30a7%5Cu30d6%5Cu30fbDNS%5Cu306e%5Cu8a2d%5Cu5b9a%5Cu304c%5Cu8aa4%5Cu3063%5Cu3066%5Cu3044%5Cu308b%5Cu3002%20%5Cu30a2%5Cu30ab%5Cu30a6%5Cu30f3%5Cu30c8%5Cu304c%5Cu5b58%5Cu5728%5Cu3057%5Cu306a%5Cu3044%5Cu3001%5Cu5951%5Cu7d04%5Cu304c%5Cu7d42%5Cu4e86%5Cu3057%5Cu3066%5Cu3044%5Cu308b%5Cu3001%5Cu524a%5Cu9664%5Cu3055%5Cu308c%5Cu3066%5Cu3044%5Cu308b%5Cu3002%22%2Cnull%2Cnull%2C%22%2F%2Fs2.googleusercontent.com%2Fs2%2Ffavicons%3Fdomain%3Dadjmpw.com%22%2C%5B%5D%2Cnull%2Cnull%2C%5B%5D%2C%22adjmpw.com%22%2Cnull%2C%5B%5D%2C%5B%5D%2C%5B%5D%2C%5B%5D%2Cnull%2Cnull%2Cnull%2Cnull%2Cnull%2Cnull%2Cnull%2Cnull%2Cnull%2Cnull%2Cnull%2Cnull%2Cnull%2Cnull%2Cnull%2Cnull%2Cnull%2Cnull%2Cnull%2Cnull%2Cnull%2Cnull%2Cnull%2Cnull%2C%5B%5D%2Cnull%2Cnull%2Cnull%2Cnull%2Cnull%2Cnull%2Cnull%2Cnull%2Cnull%2Cnull%2Cnull%2Cnull%2Cnull%2Cnull%2Cnull%2Cnull%2Cnull%2Cnull%2Cnull%2Cnull%2Cnull%2Cnull%2Cnull%2Cnull%2Cnull%2Cnull%2Cnull%2Cnull%2Cnull%2Cnull%2Cnull%2Cnull%2Cnull%2Cnull%2Cnull%2Cnull%2Cnull%2Cnull%2Cnull%2Cnull%2C%5B%5D%5D%7D%5D%2Cnull%2C%5B%5D%2C%5B%5B%5Bnull%2Cnull%2C1%5D%5D%2Cnull%5D%2Cnull%2Cnull%2Cnull%2Cnull%2Cnull%2Cnull%2C%22!A0Kqty2yd13VXUSIQmFRwsHOTgIAAACcUgAAABMqAOOd_e40c9ZGEcvCbLFeO4xd-bERNZUdpPVB47P7EAX_SOsuScB1gj-i9hJCjwcEohHLhq9-1lnTIG6wDZoXbyksjLzUxuna6V4JfCOO_eohj7MQnsKiVuhKHcHKrOqP8WDZ8dgmUIFNVubfBPNemcuPOd8eahSf-JP9-6XMqnKdNIlTWLYqQvQWfohWhqmeu6K_tFBRDoUweLCSttIlehy66khLWOebSYf8cuLx_VQRH4Mdq-P1Cc4JlKrBwwoQPW66-Tpbb11OhHDSd7uh7S-Md7NMwkJSVzfGnWZZ3ZCjc6Cgzg%22%2Cnull%2Cnull%2Cnull%2C%5B%5D%5D&at=AObGSAh9hx7LgvgMum-4aVedQIfEJa8FgA%3A1370342318767&';
    echo "<pre>";
    $game = poster($url,$string);
    echo $game[0];
    ?>

The response header for my php curl is

HTTP/1.1 403 Forbidden
Content-Type: application/json; charset=UTF-8
Content-Disposition: attachment; filename="response.txt"
Cache-Control: no-cache, no-store, max-age=0, must-revalidate
Pragma: no-cache
Expires: Fri, 01 Jan 1990 00:00:00 GMT
Date: Tue, 04 Jun 2013 10:46:03 GMT
Set-Cookie: NID=67=U68qmM7sSUNdgJY64JIEltRkmhYS7l9mTZXX7GL2Z0BpnYBgZL2FsVnjpAYUvToyBFzGY7SLGAS5Ko0K-N61I4VV7HTvIlZvX9ARxSxKR_KQtfjHDbqZ3pK_y-X7V-Oe;Domain=.google.com;Path=/;Expires=Wed, 04-Dec-2013 10:46:03 GMT;HttpOnly
P3P: CP="This is not a P3P policy! See http://www.google.com/support/accounts/bin/answer.py?hl=en&answer=151657 for more info."
X-Content-Type-Options: nosniff
X-Frame-Options: SAMEORIGIN
X-XSS-Protection: 1; mode=block
Server: GSE
Transfer-Encoding: chunked

My post content, cookie , post url ..everything is same as http header addon in firefox.(works even when i am logged out) . But why do i get 403 error in my php curl ? how google detects the curl ?

I try to download a file with wget and curl and it is rejected with a 403 error (forbidden).

I can view the file using the web browser on the same machine.

I try again with my browser’s user agent, obtained by http://www.whatsmyuseragent.com. I do this:

wget -U 'Mozilla/5.0 (X11; Linux x86_64; rv:30.0) Gecko/20100101 Firefox/30.0' http://...

and

curl -A 'Mozilla/5.0 (X11; Linux x86_64; rv:30.0) Gecko/20100101 Firefox/30.0' http://...

but it is still forbidden. What other reasons might there be for the 403, and what ways can I alter the wget and curl commands to overcome them?

(this is not about being able to get the file — I know I can just save it from my browser; it’s about understanding why the command-line tools work differently)

update

Thanks to all the excellent answers given to this question. The specific problem I had encountered was that the server was checking the referrer. By adding this to the command-line I could get the file using curl and wget.

The server that checked the referrer bounced through a 302 to another location that performed no checks at all, so a curl or wget of that site worked cleanly.

If anyone is interested, this came about because I was reading this page to learn about embedded CSS and was trying to look at the site’s css for an example. The actual URL I was getting trouble with was this and the curl I ended up with is

curl -L -H 'Referer: http://css-tricks.com/forums/topic/font-face-in-base64-is-cross-browser-compatible/' http://cloud.typography.com/610186/691184/css/fonts.css

and the wget is

 wget --referer='http://css-tricks.com/forums/topic/font-face-in-base64-is-cross-browser-compatible/' http://cloud.typography.com/610186/691184/css/fonts.css

Very interesting.

Are you looking for a solution to the PHP curl 403 forbidden error? We can help you in fixing it.

Many of our customers approach us with this curl error. this error occurs due to syntax errors in code and mod-security.

Here at Bobcares, we have seen several such PHP-related errors as part of our Server Management Services for web hosts and online service providers.

Today we’ll see the different reasons for this error to occur and their respective fixes.

How to fix PHP curl 403 forbidden errors

Now let’s take a look at how our Support Engineers resolve this error for our customers

1. Syntax errors lead to 403 forbidden error

Recently, one of our customers approached us with this error. He tried to execute the following code to download the file using a PHP curl script.

/* gets the data from a URL */
function get_data($url) {
$ch = curl_init();
$timeout = 5;
curl_setopt($ch, CURLOPT_URL, $url);
curl_close($ch);
return $data;

So, our Support Engineers rewrote the code section “function get_data($url) {” as likewise:

$returned_content = get_data('https://(website url name)');

Also, we add this User-Agent with the code.

$userAgent = 'Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; .NET CLR 1.1.4322)';
curl_setopt($ch, CURLOPT_USERAGENT, $userAgent);

This resolved the PHP curl error for him.

2. mod_security issues causing PHP cURL 403 error

In another case, we had a customer who approached us with the same error after he submitting forms that contain PHP curl.

On investigating, we found that mod_security was enabled.

The mod_security feature scans all POST requests to the web site for forbidden words that might indicate that someone is trying to hack the system.

If this feature conflicts then the Apache will end up throwing an error message.

In order to disable ‘mod_security’ for the website, we go to ‘document root’ of the website. Then we open the .htaccess file.

After that, we add the below code in it.

SecFilterEngine Off
SecFilterScanPOST Off

Finally, we save the file.

3. Incorrect coding issue

Coding errors can also cause curl errors.

Here is an example, where our customer was trying to access the site with authentication.

He used the below incorrect code and received 403 forbidden error.

HTTP/1.1 403 Forbidden
content Type; Text/plain
date: wed 27 jan 2021 14:40:19 GMT

The credentials he was using were correct but still was unable to access the site with authentication.

However, Our Bobcares Support Engineers found a solution to this error:

It requires a csrt token (on a page with a form that wants to protect, the server would generate a random string) to log in. Here, the customer didn’t provide a code to retrieve/post one.

So, we added the below syntax with the code,

curl_setopt($ch, CURLOPT_USERPWD, $username . ":" . $password);

Finally, this fixed the problem.

[Need any assistance with curl errors? – We are here to help you]

Conclusion

In short, this PHP curl error can occur due to syntax errors, mod_security issues, and also due to incorrect coding issues. Today, we saw how our Support Engineers fix this error effectively.

PREVENT YOUR SERVER FROM CRASHING!

Never again lose customers to poor server speed! Let us help you.

Our server experts will monitor & maintain your server 24/7 so that it remains lightning fast and secure.

GET STARTED

var google_conversion_label = «owonCMyG5nEQ0aD71QM»;

Answer by Mya Calhoun

Gives me a 403 Forbidden error. There’s no rules in robots.txt that should interfere. What else could I try to get the script to work, or are there any other ways I could run the script from within MediaWiki?,My solution for this was to set the User Agent option, so the cURL can pretend to be a browser . An example of this set up in php is,

Stack Overflow for Teams
Where developers & technologists share private knowledge with coworkers

,For my specific project, the server would throw a 403 error if an error occurs, but still return data. So to get around the issue, I did this:

For my specific project, the server would throw a 403 error if an error occurs, but still return data. So to get around the issue, I did this:

curl_setopt($ch, CURLOPT_FAILONERROR, 0); // Fail on errors

Answer by Kailey Gilmore

I try to download a file with wget and curl and it is rejected with a 403 error (forbidden).,Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. It only takes a minute to sign up.,but it is still forbidden. What other reasons might there be for the 403, and what ways can I alter the wget and curl commands to overcome them?,
Stack Exchange network consists of 178 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.

Tried all of the above however no luck; used dev browser tool to get user-agent string, once I added the following, success:

--user-agent="Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/51.0.2704.103 Safari/537.36"

Answer by Harry Crane

In short, this PHP curl error can occur due to syntax errors, mod_security issues, and also due to incorrect coding issues. Today, we saw how our Support Engineers fix this error effectively.,Many of our customers approach us with this curl error. this error occurs due to syntax errors in code and mod-security.,Today we’ll see the different reasons for this error to occur and their respective fixes.,Coding errors can also cause curl errors.

Recently, one of our customers approached us with this error. He tried to execute the following code to download the file using a PHP curl script.

/* gets the data from a URL */
function get_data($url) {
$ch = curl_init();
$timeout = 5;
curl_setopt($ch, CURLOPT_URL, $url);
curl_close($ch);
return $data;

So, our Support Engineers rewrote the code section “function get_data($url) {” as likewise:

$returned_content = get_data('https://(website url name)');

Also, we add this User-Agent with the code.

$userAgent = 'Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; .NET CLR 1.1.4322)';
curl_setopt($ch, CURLOPT_USERAGENT, $userAgent);

After that, we add the below code in it.

<IfModule mod_security.c>
SecFilterEngine Off
SecFilterScanPOST Off
</IfModule>

He used the below incorrect code and received 403 forbidden error.

HTTP/1.1 403 Forbidden
content Type; Text/plain
date: wed 27 jan 2021 14:40:19 GMT

So, we added the below syntax with the code,

curl_setopt($ch, CURLOPT_USERPWD, $username . ":" . $password);

Answer by Ronan Knight

Why is using cURL giving me a 403 forbidden error when file_get_contents works? ,The code above gives me a 403 error but when I use file_get_contents, I can echo the whole webpage.

This is my PHP code:

$ch = curl_init('http://www.iphonehacks.com/2016/08/jailbreak-iphone-ipad-ios-9-3-3-pangu-1-1.html'); 
curl_setopt($ch, CURLOPT_USERAGENT, "User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/51.0.2704.103 Safari/537.36");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); 
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1); 
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);

$data = curl_exec($ch);
curl_close($ch);

echo $data;

The code above gives me a 403 error but when I use file_get_contents, I can echo the whole webpage.

$data = file_get_contents('http://www.iphonehacks.com/2016/08/jailbreak-iphone-ipad-ios-9-3-3-pangu-1-1.html');

echo $data;

Answer by Romeo Ahmed

The vscode installation plug-in liveserver specified browser reported an error and could not be found,MySQL: if the remote connection using navicatip fails, prompt “is not allowed to connect to this MySQL server”,
ROS package executes rosrun error: attributeerror: ‘thread’ object has no attribute ‘isalive‘
,Under Linux, git cannot be used, prompt sign_and_send_pubkey: signing failed: agent refused operation

wget www.google.com -U "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/72.0.3626.121 Safari/537.36"

What is User Agent and how to get it, please refer to the following blog. Of course, you can also use the above one directly.
What is the UserAgent and how to view the UserAgent using the browser

 
2. Permanently change THE UA of Wget
Modify the configuration file /etc/wgetrc to add the following line:

header = User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/72.0.3626.121 Safari/537.36

The above configuration will take effect for all users. If you only want the current user to take effect, you can add the above line to ~/.wgetrc. If this file is not available, you can create it manually.

 
2. Modify the user-Agent of curl
1. Temporary change to Curl’s UA
Use the following parameters:

curl https://www.google.com --user-agent "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/72.0.3626.121 Safari/537.36"

 
2. Permanently change Curl’s UA
Modify the profile ~/.curlrc to add the following line:

–user-agent=Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/72.0.3626.121 Safari/537.36

Answer by Marshall Vincent

A 403 on shared hosting USUALLY means that there’s a permissions issue on the file you’re trying to contact. Basically, the web server is saying, «No, I’m not going to allow you to access or run login.php.» You might want to double-check the owner and permissions of that file, in case it was uploaded incorrectly somehow.,or you can check file permissions of /v2/wp-content/themes/default/images/contact-innovation-logo.png,you should check file permissions for /v2/wp-content/themes/default/images/contact-yellow-icon.png,The s3:GetObject permission is the only documented permission required for using HEAD, which seems to eliminate permissions as the problem, if GET is working, which points back to the signature as the potential issue.

My http header is below

Host: plus.google.com

Content-Type: application/x-www-form-urlencoded; 

Cookie:NID=67=pdjIQN5CUKVn0bRgAlqitBk7WHVivLsbLcr7QOWMn35Pq03N1WMy6kxYBPORtaQUPQrfMK4Yo0vVz8tH97ejX3q7P2lNuPjTOhwqaI2bXCgPGSDKkdFoiYIqXubR0cTJ48hIAaKQqiQi_lpoe6edhMglvOO9ynw; PREF=ID=52aa671013493765:U=0cfb5c96530d04e3:FF=0:LD=en:TM=1370266105:LM=1370341612:GM=1:S=Kcc6KUnZwWfy3cOl; OTZ=1800625_34_34__34_; S=talkgadget=38GaRzFbruDPtFjrghEtRw; SID=DQAAALoAAADHyIbtG3J_u2hwNi4N6UQWgXlwOAQL58VRB_0xQYbDiL2HA5zvefboor5YVmHc8Zt5lcA0LCd2Riv4WsW53ZbNCv8Qu_THhIvtRgdEZfgk26LrKmObye1wU62jESQoNdbapFAfEH_IGHSIA0ZKsZrHiWLGVpujKyUvHHGsZc_XZm4Z4tb2bbYWWYAv02mw2njnf4jiKP2QTxnlnKFK77UvWn4FFcahe-XTk8Jlqblu66AlkTGMZpU0BDlYMValdnU; HSID=A6VT_ZJ0ZSm8NTdFf; SSID=A9_PWUXbZLazoEskE; APISID=RSS_BK5QSEmzBxlS/ApSt2fMy1g36vrYvk; SAPISID=xxxxxxxxxxxxxx

The response header for my php curl is

HTTP/1.1 403 Forbidden
Content-Type: application/json; charset=UTF-8
Content-Disposition: attachment; filename="response.txt"
Cache-Control: no-cache, no-store, max-age=0, must-revalidate
Pragma: no-cache
Expires: Fri, 01 Jan 1990 00:00:00 GMT
Date: Tue, 04 Jun 2013 10:46:03 GMT
Set-Cookie: NID=67=U68qmM7sSUNdgJY64JIEltRkmhYS7l9mTZXX7GL2Z0BpnYBgZL2FsVnjpAYUvToyBFzGY7SLGAS5Ko0K-N61I4VV7HTvIlZvX9ARxSxKR_KQtfjHDbqZ3pK_y-X7V-Oe;Domain=.google.com;Path=/;Expires=Wed, 04-Dec-2013 10:46:03 GMT;HttpOnly
P3P: CP="This is not a P3P policy! See http://www.google.com/support/accounts/bin/answer.py?hl=en&answer=151657 for more info."
X-Content-Type-Options: nosniff
X-Frame-Options: SAMEORIGIN
X-XSS-Protection: 1; mode=block
Server: GSE
Transfer-Encoding: chunked

Answer by Brielle Ponce

Open Developer options using Ctrl+Shift+I.,Open the URL in either of the browser.,Now click on download. Saving file isn’t required. We only need the network activity while browser requests the file from the server.,

Business

Learn more about hiring developers or posting ads with us

An example of the command:

curl 'https://company-my.sharepoint.com/personal/path/_layouts/15/download.aspx?SourceUrl=
%2Fpersonal%2Fsome%5Fpath%5Fin%2Ffile' -H 'User-Agent: Mozilla/5.0 (X11; Ubuntu; Linux 
x86_64; rv:73.0) Gecko/20100101 Firefox/73.0' -H 'Accept: text/html,application/xhtml+xml,
application/xml;q=0.9,image/webp,*/*;q=0.8' -H 'Accept-Language: en-US,en;q=0.5' 
--compressed -H 'DNT: 1' -H 'Connection: keep-alive' -H 'Referer: https://company-my
.sharepoint.com/personal/path/_layouts/15/onedrive.aspx?id=%2Fpersonal%2Fagain%5Fa%5Fpath%2F
file&parent=%2Fpersonal%2Fpath%5Fagain%5Fin%2&originalPath=somegibberishpath' -H 
'Cookie: MicrosoftApplicationsTelemetryDeviceId=someid; 
MicrosoftApplicationsTelemetryFirstLaunchTime=somevalue; 
rtFa=rootFederationAuthenticationCookie; FedAuth=againACookie; CCSInfo=gibberishText; 
FeatureOverrides_enableFeatures=; FeatureOverrides_disableFeatures=' -H 
'Upgrade-Insecure-Requests: 1' -H 'If-None-Match: "{some value},2"' -H 'TE: Trailers' 
--output file.extension

Answer by Kaden Huber

If the error can be reproduced, use curl -v to get more details between the client and the API.,When I call my Amazon API Gateway API, I get a 403 Forbidden error. How do I troubleshoot the error?,Handling errors in Amazon API Gateway,API Gateway APIs can return 403 Forbidden responses for any of the following reasons:

curl -X GET -v https://apiId.execute-api.region.amazonaws.com/stageName/resourceName

Ошибка 403 при парсинге с помощью CURL

При программировании и автоматизации задач, связанных с получением и обработкой данных с веб-сервера, часто используется библиотека CURL. Однако, иногда при использовании CURL для парсинга веб-страниц, разработчик может столкнуться с ошибкой 403 — «Forbidden» или «Доступ запрещен».

Ошибку 403 можно получить, когда сервер не разрешает доступ к запрашиваемому ресурсу. Существуют различные причины возникновения этой ошибки, и в данной статье мы рассмотрим некоторые из них и предложим возможные решения.

1. Проверьте права доступа

Одна из наиболее распространенных причин ошибки 403 при парсинге CURLом — недостаточный уровень прав доступа для запрашиваемого ресурса. Убедитесь, что вы имеете достаточные права доступа для получения данных с сервера. Возможно, вам потребуется обратиться к администратору сервера или проверить настройки доступа к ресурсам.

2. Проверьте заголовки User-Agent

User-Agent — это строка, которая идентифицирует веб-клиента (например, браузер или скрипт). Некоторые серверы блокируют запросы без User-Agent или с неподдерживаемым значением User-Agent. Убедитесь, что вы установили допустимое значение User-Agent для вашего CURL-запроса.

Пример:

curl_setopt($curl, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537');

3. Работа через прокси

Если сервер блокирует ваш IP-адрес или подозревает вас в нежелательной активности, вы можете попробовать использовать прокси-сервер для обхода блокировки. CURL имеет возможности для работы через прокси.

Пример:

curl_setopt($curl, CURLOPT_PROXY, 'ваш_прокси');
curl_setopt($curl, CURLOPT_PROXYPORT, 'порт_прокси');

4. Использование HTTP авторизации

Если веб-сервер требует аутентификации для доступа к ресурсу, вы должны предоставить соответствующие учетные данные. Для этого вы можете использовать опцию CURLOPT_USERPWD.

Пример:

curl_setopt($curl, CURLOPT_USERPWD, 'логин:пароль');

5. Использование cookie-файлов

Некоторые серверы могут требовать наличие cookie-файлов для доступа к определенным ресурсам. Вы можете использовать опцию CURLOPT_COOKIEFILE для чтения cookie-файла и CURLOPT_COOKIEJAR для сохранения cookie-файла после получения данных.

Пример:

curl_setopt($curl, CURLOPT_COOKIEFILE, 'путь_к_файлу');
curl_setopt($curl, CURLOPT_COOKIEJAR, 'путь_к_файлу');

6. Обход CAPTCHA

В некоторых случаях сервер может требовать прохождения проверки CAPTCHA для доступа к ресурсу. Это может быть вызвано частыми запросами с одного IP-адреса или другой активностью, которая может быть похожа на бота. В таких случаях вам нужно найти способ решения CAPTCHA и включить его в свой скрипт.

7. Проверьте параметры SSL

Если вы работаете с ресурсом, который требует безопасное соединение через протокол HTTPS, убедитесь, что у вас установлено SSL-соединение. Вы можете использовать опцию CURLOPT_SSL_VERIFYPEER для включения или отключения проверки SSL-сертификата. Если у вас нет действительного сертификата, вы можете отключить проверку SSL.

Пример:

curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);

В заключение, ошибка 403 при парсинге CURLом может быть вызвана различными причинами, такими как недостаточные права доступа, ограничения на IP-адрес, блокировка скриптов или безопасность сервера. При возникновении этой ошибки важно тщательно проверить каждую из этих причин и использовать подходящие решения. Успешное решение этой проблемы позволит вам без проблем получать и обрабатывать данные с сервера и продолжить работу с вашим проектом.

Понравилась статья? Поделить с друзьями:
  • Curl 28 ошибка samsung
  • Cyberpower ошибка ch9f
  • Cups внутренняя ошибка сервера
  • Cuphead ошибка при запуске
  • Cyberpower cps600e ошибка f02 что это значит