gpt4 book ai didi

php - HTTP post 请求 objective-c

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

我正在尝试向我的服务器发出一个 http 请求,然后将其插入到 mysql 表中。我没有收到任何错误。Objective-c 返回连接成功。

在 php 脚本中没有错误,但它没有将行添加到 mysql 服务器。我已经仔细检查了表和属性名称。怎么没有加入mysql?

  if (FBSession.activeSession.isOpen) {
[[FBRequest requestForMe] startWithCompletionHandler:
^(FBRequestConnection *connection, NSDictionary<FBGraphUser> *user, NSError *error) {
if (!error) {

NSString *currentId = [user objectForKey:@"id"];
NSString *currentName = user.name;


NSString *post = [NSString stringWithFormat:@"&name=%@&id=%@",currentName,currentId];
NSData *postData = [post dataUsingEncoding:NSASCIIStringEncoding allowLossyConversion:YES];

NSString *postLength = [NSString stringWithFormat:@"%d",[postData length]];

NSMutableURLRequest *request = [[NSMutableURLRequest alloc] init];
[request setURL:[NSURL URLWithString:[NSString stringWithFormat:@"http://www.ratemyplays.com/api/post_user.php"]]];

[request setHTTPMethod:@"POST"];
[request setValue:postLength forHTTPHeaderField:@"Content-Length"];
[request setValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"Current-Type"];
[request setHTTPBody:postData];
NSURLConnection *conn = [[NSURLConnection alloc]initWithRequest:request delegate:self];
if(conn)
{
NSLog(@"Connection Successful");
}
else
{
NSLog(@"Connection could not be made");
}


}
}];

PHP 代码。

 <?php

$link = mysqli_connect("mysql12.gigahost.dk","dirts","passwordexample","dirts_api");

$name = (string)$_POST['name'];
$id = (int)$_POST['id'];

mysqli_query($link, "INSERT INTO Users (name, userID) VALUES ('$name', '$id')";


$result = mysqli_query($link,$query);

?>

最佳答案

 $name = (string)$_GET['name'];
$id = (int)$_GET['id'];

你说的是 POST?那么应该是

 $name = (string)$_POST['name'];
$id = (int)$_POST['id'];

关于php - HTTP post 请求 objective-c,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21443340/

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