将数据发送到在线Php脚本

时间:2014-07-14 10:22:50

标签: php ios uitextfield

我正在尝试将用户输入数据(从UItextfiled)转换为在线php脚本但是我似乎无法使其工作并且不确定我的错误在哪里我的编码如下;

- (IBAction)sendPost:(id)sender {
// Create your request string with parameter name as defined in PHP file
NSString *myRequestString = [NSString stringWithFormat:@"name=%@&surname=%@",_firstnameresult.text,_surnameresult.text];

// Create Data from request
NSData *myRequestData = [NSData dataWithBytes: [myRequestString UTF8String] length: [myRequestString length]];
NSMutableURLRequest *request = [[NSMutableURLRequest alloc] initWithURL: [NSURL URLWithString: @"http://mckenziedave.co.uk/client_files/gcap/test"]];
// set Request Type
[request setHTTPMethod: @"POST"];
// Set content-type
[request setValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"content-type"];
// Set Request Body
[request setHTTPBody: myRequestData];
// Now send a request and get Response
NSData *returnData = [NSURLConnection sendSynchronousRequest: request returningResponse: nil error: nil];
// Log Response
NSString *response = [[NSString alloc] initWithBytes:[returnData bytes] length:[returnData length] encoding:NSUTF8StringEncoding];
NSLog(@"%@",response);

}

和在线PHP;

<?php
 $name = $_POST['name'];
 $surname = $_POST['surname'];

echo echo $name.','.$surname;
?>

当我检查调试器时,由于某种原因它没有改变&#39;名称&#39;它加载了php。或者&#39;姓氏&#39;与田地。 我现在已经坚持了一段时间,真的不知道该怎么做......

1 个答案:

答案 0 :(得分:1)

.php扩展名添加到服务器中的test文件以及上面发布的ios程序中。