Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7402783
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T04:51:37+00:00 2026-05-29T04:51:37+00:00

I am trying to execute a curl command that I can execute successfully in

  • 0

I am trying to execute a curl command that I can execute successfully in the terminal but it fails in PHP script with the following error:

HTTP/1.1 401 Unauthorized Access-Control-Allow-Origin: * Access-Control-Request-Method: * Cache-Control: no-cache Content-Type: application/json; charset=utf-8 Date: Mon, 06 Feb 2012 00:38:56 GMT Server: nginx/1.0.4 Set-Cookie: _parse_session=XXXXXX; domain=.parse.com; path=/; expires=Sun, 06-Feb-2022 00:38:56 GMT; HttpOnly Status: 401 Unauthorized WWW-Authenticate: Basic realm=”Parse” X-Runtime: 0.002486 X-UA-Compatible: IE=Edge,chrome=1 Content-Length: 24 Connection: keep-alive {“error”:”unauthorized”}

This is the command executed in terminal that executes successfully:

curl -H “Accept: application/json” -H “X-Parse-Application-Id: XXXXXXX” -H “X-Parse-REST-API-Key: XXXXXXXXX” -X GET “https://api.parse.com/1/classes/XXXXXX”

This is the PHP code:

$fields = array('Accept: '=>'application/json',
            'X-Parse-Application-Id:' => 'XXXXX',
            'X-Parse-REST-API-Key:' => 'XXXXX');

$ch = curl_init();

curl_setopt($ch, CURLOPT_URL, 'https://api.parse.com/1/classes/XXXX');

curl_setopt($ch, CURLOPT_RETURNTRANSFER, false);
curl_setopt($ch, CURLOPT_HEADER, $fields);
curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
curl_setopt(CURLOPT_USERPWD, 'XXXXXX');

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

The interesting note is that when executed in the terminal authentication info is not required.

Help will be appreciated.

Thanks

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-29T04:51:42+00:00Added an answer on May 29, 2026 at 4:51 am

    Your header fields shouldn’t have the : in the array defnition:

    'X-Parse-REST-API-Key:' => 'XXXXX');
                         ^---remove these
    

    That makes the : part of the field name, so you’re actually sending:

    X-Parse-REST-API-Key:: XXXXX
                        ^^---note the doubled colons
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

The command I'm trying to execute from the terminal: curl http://acme.example.com/controller_name/destroy.xml?api_key=123&id=150&other_id=430 Just a simple
I'm trying to execute a SQL command, but I just can't find out why
I am trying to execute this but cant see any result: <script> function init()
I am trying to execute an SOAP-function using cURL (because I get an error
I am trying to get PHP to execute a curl connection to another server.
I trying to execute the following code... but the AlertDialog is creating problems! Without
I'm trying to execute a script named csearch.php five times with the interval of
I'm trying to execute an HTTP GET from my website to another website that
How to install RVM on lion, I am trying this command in terminal curl
While trying to execute the following lines only the last two statements are displayed(Here

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.