在試圖讓用戶輸入數據(從一個UItextfiled)到一個在線PHP腳本的過程中,但我似乎無法得到它的工作,不知道我的錯在哪裏我的編碼是作爲如下:發送數據到在線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;
?>
它加載的PHP當我檢查調試器由於某些原因而心不是同場改變「名」或「姓」。 我一直停留在這個有一段時間了,真的不知道該怎麼辦...
我一直在嘗試不同的方式一小時,但它仍然沒有改變或發送任何數據到PHP,只是加載它......任何人都可以看到我要去哪裏錯了? – user3788098