2012-01-26 5 views
3

私はiPhoneスクリプトをいくつかの配列に送信する必要があるiPhoneアプリケーションを作成しています。そして、それらの配列の値を取得し、 xmlファイル。私はPHPでxmlファイルを書く方法を知っていますが、私は、iOSアプリケーションからPHPスクリプトにデータを送信する方法がわかりません...NSMutable配列をiOSのPHPスクリプトに送信

PHPのスクリプトをiOS?申し訳ありません。私はphpとiOS(そのことに関しては一般的にプログラミングしています)にはとても新しいです。

おかげ

答えて

0

メイクGETまたはiOSアプリからのPOSTリクエスト

例:

NSURL *url = [NSURL URLWithString:@"http://www.site.com/sendData.php"]; 

     NSMutableURLRequest *theRequest = [NSMutableURLRequest requestWithURL:url 
                    cachePolicy:NSURLRequestReloadIgnoringCacheData 
                   timeoutInterval:60]; 

     [theRequest setHTTPMethod:@"POST"];  
     [theRequest setValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"Content-Type"]; 

     NSString *postData = [NSString stringWithFormat:@"name1=%@&name2=%@", data1, data2]; 

     NSString *length = [NSString stringWithFormat:@"%d", [postData length]];  
     [theRequest setValue:length forHTTPHeaderField:@"Content-Length"]; 

     [theRequest setHTTPBody:[postData dataUsingEncoding:NSASCIIStringEncoding]]; 

     NSURLConnection *sConnection = [NSURLConnection connectionWithRequest:theRequest delegate:self];  
     [sConnection start]; 

In order to download the contents of a URL, an application needs to provide a delegate object that, at a minimum, implements the following delegate methods: connection:didReceiveResponse:, connection:didReceiveData:, connection:didFailWithError: and connectionDidFinishLoading:.

about NSURLConnection about NSURLRequest

+0

-1:いくつかのより多くの情報を追加してください – Paranaix

0

タイラー、あなたは以下のコードを使用することができますデータを投稿する。 NSMutableArrayの配列を送信するために

[NSMutableURLRequest* urlRequest = [NSMutableURLRequest requestWithURL:<your php url>]; 
[urlRequest setHTTPMethod:@"POST"]; 
[urlRequest setHTTPBody:@"var1=val1&var2=val2"]; //Replace with your actual name/parm values 
[[NSURLConnection alloc] initWithRequest:urlRequest delegate:self]; 

、あなたは、配列を反復処理し、配列の文字列表現を含むNSStringのオブジェクトを作成する必要があります。次に、その文字列をhttpの本文として設定する必要があります。

関連する問題