test put JSON directly as body

This commit is contained in:
gnieark 2016-05-29 18:03:44 +02:00
parent 55e80fb781
commit 0bd456f454
4 changed files with 29 additions and 3 deletions

View File

@ -4,6 +4,9 @@
* choose by random a free column
*/
print_r($_POST);
/*
$grid=json_decode($_POST['grid']);
$colAvailable=array();
@ -16,3 +19,4 @@ for($i=0;$i<7;$i++){
shuffle($colAvailable);
echo $colAvailable[0];
die;
*/

View File

@ -84,12 +84,13 @@ switch ($_POST['act']){
'match_id' => $_SESSION['matchId']."-".$_SESSION['currentPlayer'],
'opponent' => $opponentName,
'you' => $you,
'grid' => json_encode( $_SESSION['map'])
'grid' => $_SESSION['map']
);
//send query
$anwserPlayer=get_IA_Response($botUrl,$postDatas);
//for test ***************************
echo $anwserPlayer; die;
//vérifier la validité de la réponse
if((isset($_SESSION['map'][5][$anwserPlayer])) && ($_SESSION['map'][5][$anwserPlayer] == "")){
//reponse conforme

View File

@ -1,5 +1,9 @@
<?php
function get_IA_Response($iaUrl,$postParams){
//send params JSON as body
$data_string = json_encode($postParams);
/*
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $iaUrl);
curl_setopt($ch, CURLOPT_POST, true);
@ -7,6 +11,20 @@ function get_IA_Response($iaUrl,$postParams){
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$output = curl_exec($ch);
curl_close($ch);
*/
$ch = curl_init($iaUrl);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch, CURLOPT_POSTFIELDS, $data_string);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'Content-Type: application/json',
'Content-Length: ' . strlen($data_string))
);
$output= curl_exec($ch);
curl_close($ch);
return htmlentities($output);
}
function get_Post_Params($botsCount){

View File

@ -46,7 +46,10 @@ function connectFour(bot1,bot2,xd_check, newGame){
//send request
var xhr = Ajx();
xhr.onreadystatechange = function(){if(xhr.readyState == 4){
if(xhr.status == 200) {
if(xhr.status == 200) {
//for test
alert(xhr.responseText);
try{
var reponse = JSON.parse(xhr.responseText);
}catch(e){