2011-10-20 16 views
0

私はユーザー登録できる登録ページを作っていますか? これは..............サーバーにデータを書き込む方法は?

-(IBAction)btn_log:(id)sender 
    { 

//NSString* username = nameInput.text; 
//NSString* pass = passInput.text; 

NSString* firstname = nameInput.text; 
NSString* lastname = passInput.text; 
NSString* bname = lastInput.text; 


NSString *post = 
[[NSString alloc] initWithFormat:@"fname=%@&lname=%@&email=%@",firstname,lastname,bname]; 

//NSString *post = [[NSString alloc]initWithFormat:@"fname=firstname&lname=lastname&email=bname]; 

NSData * postData = [post dataUsingEncoding:NSASCIIStringEncoding allowLossyConversion:NO]; 
NSString * postLength = [NSString stringWithFormat:@"%d",[postData length]]; 
NSMutableURLRequest * request = [[[NSMutableURLRequest alloc] init] autorelease]; 
[request setURL:[NSURL URLWithString:[NSString stringWithFormat:@"http://www.yoursite.com/file.php"]]]; 
[request setHTTPMethod:@"POST"]; 
[request setValue:postLength forHTTPHeaderField:@"Content-Length"]; 
[request setValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"Content-Type"]; 
[request setHTTPBody:postData]; 
NSURLConnection * conn = [[NSURLConnection alloc] initWithRequest:request delegate:self]; 

if (conn) NSLog(@"Connection Successful"); 
    } 

私のコードである。しかし、私が間違いを犯していた場合、誰もが私を提案することができますしてくださいので、働いていません。

+1

なぜリクエストが機能していないのか、さらに詳しい情報を提供できますか?呼び出しが失敗する可能性のある多くの異なる方法があります。 – richerd

+0

NSURLConnectionデリゲートのドキュメントを見てください – Rog

+0

私はハードコアデータをデータベースに送ることにしましたが、文字列からデータベースにデータを渡したいが行かない場合 –

答えて

0
NSURLConnection * conn = [[NSURLConnection alloc] initWithRequest:request delegate:self]; 

上記のコード行を次の行に置き換えます。おそらくそれは動作します。このように

NSData *urlData=[NSURLConnection sendSynchronousRequest:request returningResponse:&response error:&error]; 
+1

これはUIをブロックする – Rog

+0

私はそれについて知りませんアプリ私は活動指標を示している。 – Stark

1

試みは、それはあなたに

を助けるかもしれ

NSURL * URL = [NSURL URLWithString:[NSStringのstringWithFormat:@ "http://www.yoursite.com/file.php"] ]]; nsstring * body = [nsstring stringwithformat:@ "%@、%@"、nameinput、paasinput]; nsmutableurlrequest * request = [nsmutablerequest alloc] initwithurl:url];

[request setHTTPMethod:@ "POST"]; [request setValue:@ "application/x-www-form-urlencoded" forHTTPHeaderField:@ "Content-Type"]; [要求するsethttpbody:[ボディdataysubgebcidubg:asciiiencoding allowlossyconversion:true]]; [request setValue:postLength forHTTPHeaderField:@ "Content-Length"]; [setHTTPBody要求:postData]; NSURLConnection * conn = [[NSURLConnection alloc] initWithRequest:デリゲート要求:自己];

if(conn)NSLog(@ "Connection Successful");

関連する問題