gpt4 book ai didi

iPhone PLIST 文件上传即将推出二进制文件

转载 作者:塔克拉玛干 更新时间:2023-11-02 10:19:18 25 4
gpt4 key购买 nike

我有一个用 Objective C 构建的 iPhone 应用程序,它可以将 PLIST 文件从 iPhone 上传到服务器。大多数时候它工作得很好,但有时文件看起来像这样

bplist00Ú .....

我发现这显然是一个二进制 PLIST,但我不明白为什么会这样。

有什么想法吗?

NSString *path = [[NSHomeDirectory() stringByAppendingPathComponent:@"Documents"] stringByAppendingPathComponent:fileName];
NSData *data = [[NSData alloc] initWithContentsOfFile:path];

// Location ID doesn't seem to be correct here - always 0?
NSMutableString *urlString = [NSMutableString string];
[urlString appendString:[NSString stringWithFormat:@"http://www.website.com/app/iphone/submitjob/upload?jid=%i&mid=%@&lid=%i", delegate.jobInProgress.jobID, delegate.memberID, [[delegate.jobInProgress.plist objectForKey:@"locationID"] intValue]]];

NSMutableURLRequest *request = [[[NSMutableURLRequest alloc] init] autorelease];
[request setURL:[NSURL URLWithString:urlString]];
[request setHTTPMethod:@"POST"];

NSString *boundary = @"---------------------------14737809831466499882746641449";
NSString *contentType = [NSString stringWithFormat:@"multipart/form-data; boundary=%@", boundary];

[request addValue:contentType forHTTPHeaderField: @"Content-Type"];

NSMutableData *postbody = [NSMutableData data];
[postbody appendData:[[NSString stringWithFormat:@"\r\n--%@\r\n", boundary] dataUsingEncoding:NSUTF8StringEncoding]];
[postbody appendData:[[NSString stringWithFormat:@"Content-Disposition: form-data; name=\"userfile\"; filename=\"%@\"\r\n", fileName] dataUsingEncoding:NSUTF8StringEncoding]];
[postbody appendData:[[NSString stringWithString:@"Content-Type: application/octet-stream\r\n\r\n"] dataUsingEncoding:NSUTF8StringEncoding]];
[postbody appendData:[NSData dataWithData:data]];
[postbody appendData:[[NSString stringWithFormat:@"\r\n--%@--\r\n", boundary] dataUsingEncoding:NSUTF8StringEncoding]];
[request setHTTPBody:postbody];

NSData *returnData = [NSURLConnection sendSynchronousRequest:request returningResponse:nil error:nil];
NSString *returnString = [[NSString alloc] initWithData:returnData encoding:NSUTF8StringEncoding];
returnString = [returnString stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];

最佳答案

您是否正在上传 bundle 中的现有 .plist?因为项目中的所有 .plist 都转换为二进制格式。我会使用 CFPropertyListWrite 创建您从头开始上传到服务器的任何 .plist并将格式设置为 kCFPropertyListXMLFormat_v1_0。然后将生成的文件上传到您的服务器。这样,您就不会依赖于 bundle 中的格式。

关于iPhone PLIST 文件上传即将推出二进制文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5412337/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com