rockstardev
rockstardev

Reputation: 13537

Getting around "isXmlHttpRequest"?

I have a chunk of code blocking me from doing a curl call to an endpoint:

if($this->_request->isXmlHttpRequest()) {
    // Do stuff
}

How can I alter my curl call so that the request is seen as an XmlHttpRequest?

Upvotes: 1

Views: 127

Answers (2)

rockstardev
rockstardev

Reputation: 13537

This solved the problem for me:

curl_setopt($ch, CURLOPT_HTTPHEADER, array("X-Requested-With: XMLHttpRequest", "Content-Type: application/json; charset=utf-8", "__RequestVerificationToken: ".rand(100, 100000)));

Upvotes: 1

doydoy44
doydoy44

Reputation: 5782

Just an idea.
If you are sure this is an Ajax request, you can try adding:

$_SERVER ['HTTP_X_REQUESTED_WITH'] = 'XMLHttpRequest';

Upvotes: 0

Related Questions