0

I got a quize from my university in order to pass the exam. The question is

Here’s your personal URL: aHR0cHM6Ly9nZXQtY29kZS5waHA/dG9rZW49ZTk5M2I1YWQzYmVhNzc2MDNiZmIwYTg3NzAxMTBiZjY2YjFhZGU0MA==

  1. The above URL was encoded with a popular algorithm. Decode it!
  2. Make a regular HTTP POST to that URL and send the following as the “data” parameter: -a JSON-encoded associative array that has your email address as the ’email’ key
  3. Your personal code will sent back in the response

So I decoded it with base64,

Result:

https://get-code.php?token=e993b5ad3bea77603bfb0a8770110bf66b1ade40

And I am posting the data to the cur ulr as follow

$url = 'https://get-code.php?token=e993b5ad3bea77603bfb0a8770110bf66b1ade40';
$ch = curl_init($url);
$jsonData = array(
'email' => 'example@email.com'
);


$jsonDataEncoded = json_encode($jsonData);

curl_setopt($ch, CURLOPT_POST, 1);

curl_setopt($ch, CURLOPT_POSTFIELDS, $jsonDataEncoded);

curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json')); 

$result = curl_exec($ch);
extract($_POST);

And there is nothing in the result, server not responds anything

Andrew
  • 13
  • 1
  • 10
  • 1
    You sure that you can access that URL via the Interwebz and that it is not only reachable through your university's network via some DNS magic? As `.php` is no [top level domain](https://en.wikipedia.org/wiki/List_of_Internet_top-level_domains) – k0pernikus Jun 08 '17 at 14:05
  • @k0pernikus ah yes this is cutted url, if you want i can post whole url – Andrew Jun 08 '17 at 15:08
  • In your case I'd try getting the request working using just the command line `curl`, or more human friendly: [httpie](https://httpie.org/) and re-create that with php. I also find curl in php rather tedious and strongly recommend using the library [guzzle](https://github.com/guzzle/guzzle). Without knowing the exact endpoint and its API it's hard to tell from a distance what's going wrong in your use case. – k0pernikus Jun 12 '17 at 12:09
  • Another reason why your code is failing may be that the endpoint expects raw json and you might be posting the data form-encoded. See: https://stackoverflow.com/questions/11281117/x-www-form-urlencoded-vs-json-http-post – k0pernikus Jun 12 '17 at 12:09

0 Answers0