M
M
marsdenden2017-01-15 08:18:07
PHP
marsdenden, 2017-01-15 08:18:07

How to make a CORS request to another domain using PHP CURL?

The point is this.
There is a server with basic authorization. There is an example of accessing data using a jQuery login-password. It perfectly fulfills, logs in, receives data.
But, when I try to do the same in PHP, I get a whack. Browser research showed that AJAX generates two requests (which is, in general, normal for a cross-domain option).

Apparently, without an OPTIONS request, I get a whack, although I try to insert the necessary headers into the POST request

POST /login HTTP/1.1
Authorization: Basic ааааааааааа==
User-Agent: Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/54.0.2840.99 Safari/537.36
Host: needserver.com
Accept: */*
Accept-Language: ru-RU,ru;q=0.8,en-US;q=0.5,en;q=0.3
Accept-Encoding: gzip, deflate, br
Referer: http://myserver.ru
Content-Type: application/json; charset=utf-8
Content-Length: 49
Connection: keep-alive
X-Compress: 1
Access-Control-Allow-Origin: *
origin: http://myserver.ru


Apparently, the asterisk does not roll and the server tracks the previous OPTIONS /login HTTP/1.1 request, since the browser can see what Access-Control-Allow-Origin returns: myserver.ru

Here, in fact, the question is - how to generate an OPTIONS request using php curl?

php version 5.5

Answer the question

In order to leave comments, you need to log in

3 answer(s)
M
marsdenden, 2017-01-15
@marsdenden

The issue can be considered closed. The problem is not options.
answer to question
the OPTIONS request goes through fine, but the authorization still fails. I will search further

A
Alexander Aksentiev, 2017-01-15
@Sanasol

curl doesn't "respect" cors. This is a browser-only limitation.
curl debug? What does it give?
curl_error?

R
Rou1997, 2017-01-15
@Rou1997

Use Fiddler to compare and understand what is wrong, you can also design and send requests in it yourself, you can definitely send an OPTIONS request using curl, see the documentation, but this is hardly necessary, rather the problem is different.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question