Hey I'm a student who has to create an android app where you send a message and the server responds. This is what they send me:
$request = curl_init('URL');
curl_setopt_array($request, array(
CURLOPT_POST => TRUE,
CURLOPT_HTTPHEADER => array(‘Content-Type: application/json; charset=utf-8’),
CURLOPT_USERPWD => 'mail@email.com:password',
CURLOPT_POSTFIELDS => json_encode(array('message' => 'Hey')),
CURLOPT_SSL_VERIFYPEER => FALSE, // do not verify certificate for https
CURLOPT_RETURNTRANSFER => 1, // return response as string instead of outputting it
));
$response = curl_exec($request);
- It has to send a POST request
- Username and password has to be in the header
- body has to have JSON, example { “message”: “Hey” }
- It receives JSON which contains the attributes
message
andaction
I have looked everywhere and i couldn't find a good example also this is the first time I'm doing anything like this. Thanks for the help!