test put JSON directly as body
This commit is contained in:
parent
55e80fb781
commit
0bd456f454
|
@ -4,6 +4,9 @@
|
||||||
* choose by random a free column
|
* choose by random a free column
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
print_r($_POST);
|
||||||
|
|
||||||
|
/*
|
||||||
$grid=json_decode($_POST['grid']);
|
$grid=json_decode($_POST['grid']);
|
||||||
|
|
||||||
$colAvailable=array();
|
$colAvailable=array();
|
||||||
|
@ -16,3 +19,4 @@ for($i=0;$i<7;$i++){
|
||||||
shuffle($colAvailable);
|
shuffle($colAvailable);
|
||||||
echo $colAvailable[0];
|
echo $colAvailable[0];
|
||||||
die;
|
die;
|
||||||
|
*/
|
|
@ -84,12 +84,13 @@ switch ($_POST['act']){
|
||||||
'match_id' => $_SESSION['matchId']."-".$_SESSION['currentPlayer'],
|
'match_id' => $_SESSION['matchId']."-".$_SESSION['currentPlayer'],
|
||||||
'opponent' => $opponentName,
|
'opponent' => $opponentName,
|
||||||
'you' => $you,
|
'you' => $you,
|
||||||
'grid' => json_encode( $_SESSION['map'])
|
'grid' => $_SESSION['map']
|
||||||
|
|
||||||
);
|
);
|
||||||
//send query
|
//send query
|
||||||
$anwserPlayer=get_IA_Response($botUrl,$postDatas);
|
$anwserPlayer=get_IA_Response($botUrl,$postDatas);
|
||||||
|
//for test ***************************
|
||||||
|
echo $anwserPlayer; die;
|
||||||
//vérifier la validité de la réponse
|
//vérifier la validité de la réponse
|
||||||
if((isset($_SESSION['map'][5][$anwserPlayer])) && ($_SESSION['map'][5][$anwserPlayer] == "")){
|
if((isset($_SESSION['map'][5][$anwserPlayer])) && ($_SESSION['map'][5][$anwserPlayer] == "")){
|
||||||
//reponse conforme
|
//reponse conforme
|
||||||
|
|
|
@ -1,5 +1,9 @@
|
||||||
<?php
|
<?php
|
||||||
function get_IA_Response($iaUrl,$postParams){
|
function get_IA_Response($iaUrl,$postParams){
|
||||||
|
//send params JSON as body
|
||||||
|
|
||||||
|
$data_string = json_encode($postParams);
|
||||||
|
/*
|
||||||
$ch = curl_init();
|
$ch = curl_init();
|
||||||
curl_setopt($ch, CURLOPT_URL, $iaUrl);
|
curl_setopt($ch, CURLOPT_URL, $iaUrl);
|
||||||
curl_setopt($ch, CURLOPT_POST, true);
|
curl_setopt($ch, CURLOPT_POST, true);
|
||||||
|
@ -7,6 +11,20 @@ function get_IA_Response($iaUrl,$postParams){
|
||||||
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
|
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
|
||||||
$output = curl_exec($ch);
|
$output = curl_exec($ch);
|
||||||
curl_close($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);
|
return htmlentities($output);
|
||||||
}
|
}
|
||||||
function get_Post_Params($botsCount){
|
function get_Post_Params($botsCount){
|
||||||
|
|
|
@ -47,6 +47,9 @@ function connectFour(bot1,bot2,xd_check, newGame){
|
||||||
var xhr = Ajx();
|
var xhr = Ajx();
|
||||||
xhr.onreadystatechange = function(){if(xhr.readyState == 4){
|
xhr.onreadystatechange = function(){if(xhr.readyState == 4){
|
||||||
if(xhr.status == 200) {
|
if(xhr.status == 200) {
|
||||||
|
//for test
|
||||||
|
alert(xhr.responseText);
|
||||||
|
|
||||||
try{
|
try{
|
||||||
var reponse = JSON.parse(xhr.responseText);
|
var reponse = JSON.parse(xhr.responseText);
|
||||||
}catch(e){
|
}catch(e){
|
||||||
|
|
Loading…
Reference in New Issue
Block a user