2013-03-06 42 views
0

我正在關注視頻tutorail在線發送數據到一個php文件,然後將其存儲在數據庫中。發送數據Iphone到PHP NSUTF8StringEncoding

我真的很困惑它如何工作作爲theres不張貼?它只是從變量收集信息。我幾個YouTube的評論說同樣的事情,但一些他的作品?

到目前爲止我的代碼...

- (IBAction)Submit:(id)sender { 

    NSString *strURL = [NSString stringWithFormat:@"http://www.bigwavemedia.co.uk/ios/contact.php?name=%@", nameField.text]; 

    //to execute php code 
    NSData *dataURL = [NSData dataWithContentsOfURL:[NSURL URLWithString:strURL]]; 

    NSString *strRes = [[NSString alloc] initWithData:dataURL encoding:NSUTF8StringEncoding]; 

    NSLog(@"%@", strRes); 
} 

當我點擊提交按鈕,埃文但其拉上我沒有得到任何迴應?

+0

http://www.youtube.com/watch?v=LwCyaGoRNWM – Brent 2013-03-06 14:18:56

+0

通過get方法或post方法檢查數據gat到php? – iPatel 2013-03-06 14:28:38

+0

的PHP是好的,我只需要制定出什麼添加到此代碼的末尾發送字符串一次提交已被按下。 – Brent 2013-03-06 14:29:50

回答

1

在您的情況下,您需要創建NSURLConnection與服務器通信。

NSString *strURL=[NSString stringWithFormat:@"http://www.bigwavemedia.co.uk/ios/contact.php?name=%@", nameField.text]; 

NSURL *url=[NSURL URLWithString:strURL]; 
self.request=[NSURLRequest requestWithURL:url]; 

self.nsCon=[[NSURLConnection alloc] initWithRequest:request delegate:self]; 

      if(self.nsCon) 
       self.receivedData=[[NSMutableData alloc] init]; 
      else 
      { 
       UIAlertView *alert = [[UIAlertView alloc] initWithTitle:NSLocalizedString(@"Error",@"") message:NSLocalizedString(@"Not Connected Other View !!",@"") delegate:nil cancelButtonTitle:NSLocalizedString(@"OK",@"") otherButtonTitles:nil]; 
       [alert show]; 
       [alert release]; 
      } 

而寫要求代理方法NSURLConnection,在上面的鏈接描述。

+0

我在哪裏添加此代理?我打開.h文件並添加@interface ContactViewControler:UIViewController 是否正確? – Brent 2013-03-06 14:51:19

+0

是的......這是正確的..或許多谷歌搜索它:)謝謝:) – iPatel 2013-03-06 14:54:03

+0

對不起,我最後一點困惑?謝謝 – Brent 2013-03-06 14:54:09