タイトルはほとんどそれをすべて言います。私のアプリには、次の場所にあるファイル myFile.ext の URL とパスワードがあります。
https://myserver.com/stuff.cgi?db=mydb
UIApplication の canOpenURL および openURL メソッドに渡されると、適切な動作が得られる NSURL オブジェクトを作成したいと考えています。
これは可能ですか?もしそうなら、どのように?また、注意すべきセキュリティ上の問題はありますか?
明確化のために編集:
次のコードは URL 要求を生成し、サーバーに送信されると、アプリは正常にファイルをダウンロードします。しかし、私がやりたいのは、openURL で開くことです。
+ (NSMutableURLRequest *) requestForFileNamed: (NSString *) filename {
NSString *url = [NSString stringWithFormat:@"%@&user=%@&getbinfile=%@", serverLocation, username, filename];
NSString *body = [NSString stringWithFormat:@"password=%@", password];
return [XMLRequestBuilder postRequestWithURL:url body:body];
}
XMLRequestBuilder メソッド:
+ (NSMutableURLRequest *) requestWithURL: (NSString *) url body: (NSString *) body method: (NSString *) method {
NSURL * theURL = [NSURL URLWithString:url];
NSMutableURLRequest * ret = [NSMutableURLRequest requestWithURL:theURL];
[ret setHTTPBody:[body dataUsingEncoding:NSUTF8StringEncoding]];
[ret setHTTPMethod: method];
[ret setTimeoutInterval:kDefaultTimeoutInterval];
return ret;
}
+ (NSMutableURLRequest *) postRequestWithURL: (NSString *) url body: (NSString *) body {
return [XMLRequestBuilder requestWithURL:url body:body method:@"POST"];
}