Jump to content
Fórum Script Brasil
  • 0

Como posso ter certeza q a requisição foi enviada?


Question

Nunca fiz requisição http antes mas queria participar do desafio da codenation, o desafio era solicitar pra essa api um json e criar um algoritmo pra decifrar a encriptação desse texto numa variavel dentro do json e depois enviar de volta. O algoritmo ta certo mas eu não sei se o meu codigo foi enviado. Eu abri o terminal e dei  um

php nome-do-arquivo.php

Eis o codigo:

<?php

$token ="token";
$url_receive = "https://api.codenation.dev/v1/challenge/dev-ps/generate-data?token=".$token;


$ch = curl_init();


$opts = [
CURLOPT_URL => $url_receive,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_SSL_VERIFYPEER=> false
];
curl_setopt_array($ch, $opts);


$response = curl_exec($ch);


$answer = fopen("answer.json", "wr");
fwrite($answer,$response);
fclose($answer);


$json = json_decode($response, true);
$text = $json['cifrado'];
$text = str_split($text);
$offset = $json['numero_casas'];
$tot = count($text);
$finaltext = "";


for($i = 0; $i<$tot ;$i++)
{
if(ord($text[$i]) >= 97 && ord($text[$i]) <= 122)
{
$finalchar = ord($text[$i]) + $offset;
while($finalchar > 122)
{
$finalchar -= 26;
}
$finaltext .= chr($finalchar);
}
else{
$finaltext .= $text[$i];
}

}


$json['decifrado'] = $finaltext;
$json['resumo_criptografico'] = sha1($finaltext);
$answer = fopen("answer.json", "wr");
fwrite($answer,json_encode($json));
fclose($answer);


$url_send = "https://api.codenation.dev/v1/challenge/dev-ps/submit-solution?token=".$token;


$file = new CURLFile ("answer.json","application/json","answer");
$data = array('file' => $file);


$ci = curl_init();


$opt = [
CURLOPT_URL => $url_send,
CURLOPT_POST => 1,
CURLOPT_HTTPHEADER => ["content-Type:multipart/form-data"],
CURLOPT_POSTFIELDS => $data,
CURLOPT_RETURNTRANSFER => true,
];


curl_setopt_array($ci, $opt);


$response = curl_exec($ci);
curl_close($ci);
curl_close($ch)

Obviamente eu alterei o token pra postar aq. alguém pode me dizer no que q eu errei?

Edited by lib-yasmin
Link to post
Share on other sites

0 answers to this question

Recommended Posts

There have been no answers to this question yet

Join the conversation

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

Guest
Answer this question...

×   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.

Cloud Computing


  • Forum Statistics

    • Total Topics
      148691
    • Total Posts
      644531
×
×
  • Create New...