简体   繁体   English

在iPhone的服务器上上传plist文件

[英]upload plist file on server in iphone

i have created a plist file other than the default one that exists. 我创建了一个plist文件,而不是存在的默认文件。 Can i upload this plist file onto the server 我可以将此plist文件上传到服务器上吗

I tried ASIFormDataRequest. 我尝试了ASIFormDataRequest。 I was able to upload the image and text file but when i try it with plist it throws error at point shown in bold: 我能够上传图像和文本文件,但是当我尝试使用plist时,它会在以粗体显示的点抛出错误:

Code: 码:

networkQueue = [[ASINetworkQueue queue] retain];

NSString *filePath = [[[NSBundle mainBundle] 
resourcePath] stringByAppendingPathComponent:
[@"test" stringByAppendingString:@".plist"]];

ASIFormDataRequest *request =[ASIFormDataRequest 
requestWithURL:[NSURL URLWithString:@"http://allseeing-i.com/ignore"]];

[request setPostValue:@"my_test" forKey:@"share_test"];


[request setFile:filePath 
withFileName:[test stringByAppendingString:
@".plist"] andContentType:@"propertylist/plist" forKey:@"mytest"];

[request setDelegate:self];
[request setDidFailSelector:@selector(requestFailed:)];
[request setDidFinishSelector:@selector(gotTheResponse:)];

[networkQueue addOperation: request];

[networkQueue go];

is it really possible? 真的有可能吗? or should i go ahead with xml though plist is also an xml format 还是我应该继续使用xml,尽管plist也是xml格式

but still i want to know and what should i do? 但我仍然想知道,该怎么办?

I got mine to work. 我有工作。 Hope this helps somebody :) 希望这对某人有帮助:)

NSString *filePath = [[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:
[@"test" stringByAppendingString:@".plist"]];
NSDictionary *plist = [[NSDictionary alloc] initWithContentsOfFile:path];
NSData *data = [NSPropertyListSerialization dataFromPropertyList:plist format:NSPropertyListXMLFormat_v1_0 errorDescription:nil];
ASIFormDataRequest *request = [ASIFormDataRequest requestWithURL:[NSURL URLWithString:@"yourUrl"]];
[request addData:data withFileName:@"test.plist" andContentType:@"propertylist/plist" forKey:@"file"];
[request setDelegate:self];
[request startAsynchronous];
networkQueue = [[ASINetworkQueue queue] retain];

[UIApplication sharedApplication].networkActivityIndicatorVisible = NO;

NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
[formatter setDateFormat:@"yyyy-MM-dd HH:mm:ss"];       
dateString = [formatter stringFromDate:[NSDate date]];

[formatter release];

// hyphen(-) joins file name with the timestamp for uniqueness

NSString *theme_name1 = [[[theme_name stringByAppendingString:@"-"] 
                stringByAppendingString:dateString] 
                stringByReplacingOccurrencesOfString:@" "  withString:@"_" ];



NSArray *paths =  NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,
                                                      NSUserDomainMask, YES);


NSString *documentsPath = [paths objectAtIndex:0]; 
NSString *path = [documentsPath stringByAppendingPathComponent:
                    [file_name stringByAppendingString:@".plist"]];
id plist = [[NSDictionary alloc] initWithContentsOfFile:path];



NSData *xmlData = [NSPropertyListSerialization dataFromPropertyList:plist 
                    format:NSPropertyListXMLFormat_v1_0 errorDescription:nil];
NSString *xml_string = [[NSString alloc] initWithData:xmlData 
                                         encoding:NSUTF8StringEncoding];


NSURL *url = [NSURL URLWithString:@"myurl"];
ASIFormDataRequest *request = [ASIFormDataRequest requestWithURL:url];
[request setPostValue:@"file_name1 forKey:@"filename"];
[request setPostValue:@"user" forKey:@"sharedby"];
[request setPostValue:xml_string forKey:@"data"];
[request setUsername:@"hello"];
[request setPassword:@"world"];
[request setDelegate:self];
[request setDidFailSelector:@selector(requestFailed:)];
[request setDidFinishSelector:@selector(gotTheResponse:)];
[networkQueue addOperation:request];
[networkQueue go];

If you are correct that xml and text files are fine with the above code then the most likely explanation would seem to be that either the path to the plist file is incorrect, or the file permissions don't allow the file to be read. 如果使用上述代码正确确定xml和文本文件正确,则最可能的解释似乎是plist文件的路径不正确,或者文件权限不允许读取该文件。

You can enable debug in ASIHTTPRequestConfig.h that might reveal more about what's going on. 您可以在ASIHTTPRequestConfig.h中启用调试,这可能会揭示更多有关正在发生的事情。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM