我正在开发一个应用程序,我需要使用 php Web 服务将一些长文本保存到 mysql 数据库。我已经创建了 Web 服务,但我无法将参数从 iphone 发送到 php Web 服务。以下是我的网络服务代码:
<?php
require_once('config.php');
$username = $_POST["username"];
$aboutme = $_POST["aboutme"];
$conn = mysql_connect(DB_HOST, DB_USER, DB_PASSWORD) or die('Connection to database failed: ' . mysql_error());
mysql_select_db(DB_DATABASE) or die ('select_db failed!');
$query = "insert into Member(username, aboutMe) values(.'".$username."', '".$aboutme."')";
echo $query;
$result = mysql_query($query) or die(mysql_error());
echo $result;
mysql_close($con);
?>
我找到了将数据发布到 Web 服务的代码,但我无法将数据添加到发布请求。
status=[NSString stringWithFormat:@"username=%@&password=%@&interestedIn=%@&aboutme=%@&profilePic=%@&isFBLogin=%@&useFacebookPic=%@",[@"aaaaaaaaaa" stringByAddingPercentEscapesUsingEncoding:NSASCIIStringEncoding],[@ "bbbbbb" stringByAddingPercentEscapesUsingEncoding:NSASCIIStringEncoding],[@"female" stringByAddingPercentEscapesUsingEncoding:NSASCIIStringEncoding],[@"about meeeeeeeee" stringByAddingPercentEscapesUsingEncoding:NSASCIIStringEncoding],[@"profile.png" stringByAddingPercentEscapesUsingEncoding:NSASCIIStringEncoding],[@"0" stringByAddingPercentEncoding],[@"0" stringByAddingPercentEncoding ,[@"0" stringByAddingPercentEscapesUsingEncoding:NSASCIIStringEncoding]]; //状态=@“用户名=pankaj1234&
NSString *postLength = [NSString stringWithFormat:@"%d", [postData length]];
NSMutableURLRequest *request = [[[NSMutableURLRequest alloc] init] autorelease];
NSURL *url = [NSURL URLWithString:[NSString stringWithFormat:@"http://www.domain.com/registerUser.php"]];
[request setURL:url];
[request setHTTPMethod:@"POST"];
[request setValue:postLength forHTTPHeaderField:@"Content-Length"];
[request setValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"Content-Type"];
[request setHTTPBody:postData];
NSURLResponse *response;
NSError *error;
[NSURLConnection sendSynchronousRequest:request returningResponse:&response error:&error];
NSLog(@"success!");
我将如何将这些值添加到请求中?有人可以帮帮我吗?
谢谢潘卡伊
_