0

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 and action

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!

James Hunt
  • 2,448
  • 11
  • 23
domen1
  • 1
  • 3
  • That looks like PHP code not android code? Do you want to convert PHP code to android? What have you done? – Niko Adrianus Yuwono Oct 22 '14 at 07:30
  • Yes it is. He has given me this example and i can't figure it out how to connect to it. – domen1 Oct 22 '14 at 07:32
  • possible duplicate of [Sending and Parsing JSON in Android](http://stackoverflow.com/questions/2818697/sending-and-parsing-json-in-android) – Nikola Oct 22 '14 at 07:35
  • Have a look at Retrofit here: http://square.github.io/retrofit/ It gives you the tool to make a POST request with a JSON as body. Read the documentation, it's fairly easy to use. – David Corsalini Oct 22 '14 at 07:35

0 Answers0