Cocoa Touchのサーバーからデータをアップロード/ダウンロードする方法を教えてください。私がこれまで持っているものここではこれがここでカバーされているCocoa Touchを使用してサーバーからデータをアップロードしてダウンロードしますか?
0
A
答えて
0
私は迷ってしまいました
-(void)uploadSchedule:(id)sender
{
NSData *content = [NSData dataWithContentsOfFile:self.dataFilePath];
NSString *stuff = [[NSString alloc] initWithData:content encoding:NSASCIIStringEncoding];
NSURL *url = [NSURL URLWithString:@"http://thetis.lunarmania.com"];
NSMutableURLRequest* urlRequest = [[NSMutableURLRequest alloc]initWithURL:url];
[urlRequest setHTTPMethod:@"POST"];
[urlRequest setHTTPBody:[stuff dataUsingEncoding:NSASCIIStringEncoding]];
NSLog(@"great success!");
}
-(void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response
{
// this method is called when the server has determined that it
// has enough information to create the NSURLResponse
// it can be called multiple times, for example in the case of a
// redirect, so each time we reset the data.
// receivedData is declared as a method instance elsewhere
[receivedData setLength:0];
}
-(void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data
{
// append the new data to the receivedData
// receivedData is declared as a method instance elsewhere
[receivedData appendData:data];
}
-(void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error
{
// release the connection, and the data object
[connection release];
// receivedData is declared as a method instance elsewhere
[receivedData release];
// inform the user
NSLog(@"Connection failed! Error - %@ %@",
[error localizedDescription],
[[error userInfo] objectForKey:NSErrorFailingURLStringKey]);
}
-(void)connectionDidFinishLoading:(NSURLConnection *)connection
{
// do something with the data
UIImage *image = [[UIImage alloc] initWithData:receivedData];
[cat setImage:image];
[image release];
// receivedData is declared as a method instance elsewhere
NSLog(@"Succeeded! Received %d bytes of data",[receivedData length]);
// release the connection, and the data object
[connection release];
[receivedData release];
}
-(void)connection:(NSURLConnection *)connection
didReceiveAuthenticationChallenge:(NSURLAuthenticationChallenge *)challenge
{
if ([challenge previousFailureCount] == 0) {
NSURLCredential *newCredential;
newCredential=[NSURLCredential credentialWithUser:@"[email protected]"
password:@"icanican"
persistence:NSURLCredentialPersistenceNone];
[[challenge sender] useCredential:newCredential
forAuthenticationChallenge:challenge];
} else {
[[challenge sender] cancelAuthenticationChallenge:challenge];
// inform the user that the user name and password
// in the preferences are incorrect
//[self showPreferencesCredentialsAreIncorrectPanel:self];
}
}
... ...です:
NSURLRequest - encode url for NSURLRequest POST Body (iPhone objective-C)
受け入れ答えがあるASIHTTPRequestを使用しています私が使ったものに似ていて、HTMLフォームから投稿/取得するのが本当に簡単です。ここでの例では、コードがクラッシュした上で、リリースconnection
ますので(過去stackoverflowのから)
ASIFormDataRequest *request = [[[ASIFormDataRequest alloc] initWithURL:@"http://someSite.com"] autorelease];
[request setPostValue:@"myValue1" forKey:@"myFormField1"];
[request setPostValue:@"myValue2" forKey:@"myFormField2"];
// etc.
[request start];
NSError *error = [request error];
if (!error)
NSString *response = [request responseString];
1
です。 Cocoa memory management rulesを確認します。
それ以外に、あなたはそれに伴う問題についてより具体的に説明しなければなりません。
ところで、この用語は「インスタンス変数」であり、「メソッドインスタンス」ではありません。インスタンス変数はインスタンス内部の変数であり、メソッドとは関係ありません。
0
ファイルが大きい場合は、を使用して、追加する代わりにdidReceiveData
の中にデータを書き込む方がよいでしょう。
関連する問題
- 1. JSONを使用してサーバーから重いデータをダウンロードしています
- 2. Cocoa-TouchでDocumentsディレクトリからダウンロードしたビデオを再生する
- 3. beginBackgroundTaskWithExpirationHandler、サーバーからデータをダウンロードしています
- 4. APIエラー:PHPを使用してサーバーからVimeoにビデオをアップロード
- 5. Cocoa Touch:ビデオファイルから静止画フレームをキャプチャしますか?
- 6. plist/XMLを使用して詳細データをダウンロードしてキャッシュしますか?
- 7. Cocoa TouchのカノニカルNSUnicodeStringEncodingは何を意味していますか?
- 8. javaを使用してExcelファイルからデータベースにデータをアップロード
- 9. PHPのPOSTデータを使用してJavaに.pngをサーバーにアップロード
- 10. Cocoa APIを使用してダウンロードを加速するには
- 11. サーバーからダウンロードファイルをダウンロードします。
- 12. サーバーからデータをダウンロード
- 13. フラッシュボイス録音してからサーバーにアップロード
- 14. セレンを使用してデータをダウンロード
- 15. java:POST、サーバーコードの問題を使用してHTTPサーバーにファイルをアップロードしますか?
- 16. Cocoaのレイアウトコンテナとしてテーブルを使用しますか?
- 17. ASP.NET MVCファイルをアップロードしてフルサイトをダウンロードしますか?
- 18. Delphiを使用してWebサーバーからファイルのフォルダをダウンロードするには
- 19. Javaソケットを使用してサーバーからファイルをダウンロードする方法は?
- 20. Javaを使用してIEのサーバーからxmlファイルをダウンロードする方法は?
- 21. Cocoaを使用してHTTP Webサーバーを構築する
- 22. htmlagilitypackを使用してhttps URLからHTMLデータをダウンロードできません。
- 23. PHP:基本認証を使用して別のWebサーバーからファイルをダウンロードしますか?
- 24. 作成してJava Web Launcherをダウンロードし、Webサーバーからファイルをダウンロードして実行してください
- 25. PHPを使用してAndroidManifest.xmlからデータを抽出します
- 26. YouTubeはFTPを使用してアップロードしていますか?
- 27. Webサービスを使用してサーバーにデータを挿入します。
- 28. Webサーバーからのデータをストリーミングしてvb.netとcgiを使用しよう
- 29. PHPからJSONデータを返し、JavaScriptを使用して使用します
- 30. 音楽ファイルをサーバーにアップロードしますが、ダウンロードは制限しますか?