gpt4 book ai didi

php - AFNetworking 2.0 + PHP 简单 HTTPRequest

转载 作者:行者123 更新时间:2023-11-29 12:53:19 25 4
gpt4 key购买 nike


我试过在网上搜索,但找不到专门针对我的问题的答案。我正在使用 AFNetworking 发送一个简单的 POST HTTP 请求。下面的代码产生以下结果:

 $$da39a3ee5e6b4b0d3255bfef95601890afd8070##!!
CREATE TABLE $$da39a3ee5e6b4b0d3255bfef95601890afd80709##!!
(question VARCHAR(255), answer VARCHAR(255), choices VARCHAR(255), sentBy VARCHAR(255));
INSERT INTO games (gameId, player1, player2, turn) VALUES ('$$da39a3ee5e6b4b0d3255bfef95601890afd80709##!!', '', '','');

我正在使用 sha1(),因此 $$da39a3ee5e6b4b0d3255bfef95601890afd80709
这是我的 Objective-C 代码:

AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
NSDictionary *params = @{@"gameId" : datas[0], @"p1": datas[1], @"p2":datas[2], @"turn":datas[3] };
manager.requestSerializer = [AFHTTPRequestSerializer serializer];
manager.responseSerializer = [AFHTTPResponseSerializer serializer];
[manager POST:@"http://localhost/AnswerThisPHP/newgame.php"
parameters:params
success:^(AFHTTPRequestOperation *operation, id responseObject) {
NSLog(@"JSON: %@", responseObject);
}
failure:^(AFHTTPRequestOperation *operation, NSError *error) {
NSLog(@"Error: %@", error);
}];



还有我的 PHP 代码:

    $db = "db";
$host = 'host';
$username = "username";
$password = 'password';
$link = mysql_connect($host,$username,$password);
if (!$link) {
die('Could not connect: ' . mysql_error());
echo ("Error - " . mysql_error());
}
//Seleccionamos la BBDD
@mysql_select_db($db);
//Creamos un array para almacenar los resultados
$p1 = $_GET['p1'];
$p2 = $_GET['p2'];
$gameID = $_GET['gameId'];
$gameIDSHA = "".$gameID."$$".sha1($gameID)."##".$p1."!!".$p2."";
$turn = $_GET['turn'];
$querystring = "CREATE TABLE ".$gameIDSHA." (question VARCHAR(255), answer VARCHAR(255), choices VARCHAR(255), sentBy VARCHAR(255));";
$querystring2 = "INSERT INTO games (gameId, player1, player2, turn) VALUES ('".$gameIDSHA."', '".$p1."', '".$p2."','".$turn."');";
echo $gameIDSHA;
echo '<br/>';
echo $querystring;
echo '<br />';
echo $querystring2;

$insert = mysql_query($querystring);
$insert2 = mysql_query($querystring2);

echo $insert;
echo $insert2;

最佳答案

您正在客户端发送 POST 但您正在尝试通过 GET 访问它,请使用 $_POST而不是 $_GET

关于php - AFNetworking 2.0 + PHP 简单 HTTPRequest,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21868627/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com