Jump to content

using curl

Recommended Posts

<!-- first of all completely sorry if this is not the right forum to ask this. but i've no idea which is the right forum for this --->

hello all!

i was learning how to use back4app parse on my website. while going through documentation on parseplatform.org, i found a sample block as below..

curl -X POST \
  -H "X-Parse-Application-Id: APPLICATION_ID" \
  -H "X-Parse-REST-API-Key: ${REST_API_KEY}" \
  -H "X-Parse-Revocable-Session: 1" \
  -H "Content-Type: application/json" \
  -d '{"username":"cooldude6","password":"p_n7!-e8","phone":"415-392-0202"}' \

but i could not understand how to implement this on my php code.

this might be because i am completely unfamiliar to curl.

UPDATE: while searching the web for more about uses of curl, i found something else that doesn't match the above format given by parseplatform.org. this blew my head more.

please someone help me understand all these things.

Edited by funbinod
Link to post
Share on other sites

That's the curl command line tool. If you want to use their service with PHP, the easiest way is to use their PHP SDK. Most likely they have clear documentation in their tutorials for the PHP SDK.

If you want to use PHP's implementation of curl, you'll have to learn to translate the command line language to PHP. All of this can be done by setting options with the curl_setopt() method. The manual page has a list of all the possible options.
In the example you posted, it starts by indicating that the method is POST. In PHP the option for that is CURLOPT_POST. The following four items are HTTP headers. You can add  headers in PHP using the CURLOPT_HTTPHEADER option. Following that is the request  body, this would go in th

// Information needed for the request
$data = [
  'username' => 'cooldude6',
  'password' => 'p_n7!-e8',
  'phone' => '415-392-0202'

// Send a cURL request
$request = curl_init('http://parseapi.back4app.com/parse/users');
curl_setopt(CURLOPT_POST, true); // This is a POST request
  'X-Parse-Application-Id: APPLICATION_ID',
  'X-Parse-REST-API-Key: ' . $api_key,
  'X-Parse-Revocable-Session: 1',
  'Content-Type: application/json'
curl_setopt(CURLOPT_POSTFIELDS, json_encode($data));

By default, PHP prints the curl response straight to the browser. If you want to store the result in a variable instead, you should read the PHP manual on how to use the CURLOPT_RETURNTRANSFER option.

Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Create New...