- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我使用了NSMutableString
并使用了appendFormat
函数,appendFormat设置了边界和第一个图像,并且没有追加任何其他项目,我不知道错误在哪里。
导致调试:-
2016-03-08 15:52:56.385 PropertyTurkey [474:82387]
正文----- = ----- 011000010111000001101001
Content-Disposition:表单数据; name =“image []”;
filename =“/ var / mobile / Containers / Data / Application / A3EA5D3E-377E-4E16-9541-580BB57E211E / Documents / 1.jpg”
ÿØÿà
NSDictionary *headers = @{ @"content-type": @"multipart/form-data; boundary=---011000010111000001101001",
@"cache-control": @"no-cache" };
NSArray *parameters = @[ @{ @"name": @"image[]", @"fileName":[NSString stringWithFormat:@"%@",_chosenImagesPath[0]]},
@{ @"name": @"image[]", @"fileName":[NSString stringWithFormat:@"%@",_chosenImagesPath[1]]},
@{ @"name": @"image[]", @"fileName":[NSString stringWithFormat:@"%@",_chosenImagesPath[2]]},
@{ @"name": @"image[]", @"fileName":[NSString stringWithFormat:@"%@",_chosenImagesPath[3]]},
@{ @"name": @"image[]", @"fileName":[NSString stringWithFormat:@"%@",_chosenImagesPath[4]]},
@{ @"name": @"rea_title", @"value": [NSString stringWithFormat:@"%@",_realEstateTitle] },
@{ @"name": @"why_buy_property", @"value": @"why_buy_property" },
@{ @"name": @"cit_id", @"value": [NSString stringWithFormat:@"%@",_cit_id] },
@{ @"name": @"are_id", @"value": [NSString stringWithFormat:@"%@",_are_id] },
@{ @"name": @"garden_exterior", @"value":[NSString stringWithFormat:@"%@",_desOfGardenAndExter] },
@{ @"name": @"home_interior", @"value":[NSString stringWithFormat:@"%@",_desOfHomeInterior] },
@{ @"name": @"property_desc", @"value":[NSString stringWithFormat:@"The property desc field is required."] },
@{ @"name": @"typ_id", @"value": [NSString stringWithFormat:@"%@",_typ_id] },
@{ @"name": @"rea_bedrooms", @"value": [NSString stringWithFormat:@"%@",_bedrooms] },
@{ @"name": @"rea_bathrooms", @"value": [NSString stringWithFormat:@"%@",_bathrooms]},
@{ @"name": @"rea_living_space", @"value": [NSString stringWithFormat:@"%@",_livingSpaceSqm] },
@{ @"name": @"sta_id", @"value": [NSString stringWithFormat:@"%@",_sta_id]},
@{ @"name": @"rea_price", @"value": [NSString stringWithFormat:@"%@",_price]} ];
NSString *boundary = @"---011000010111000001101001";
NSError *error;
NSMutableString *body = [[NSMutableString alloc]init];
for (NSDictionary *param in parameters) {
[body appendFormat:@"--%@\r\n", boundary];
if (param[@"fileName"]) {
[body appendFormat:@"Content-Disposition:form-data; name=\"%@\"; filename=\"%@\"\r\n", param[@"name"], param[@"fileName"]];
//[body appendFormat:@"Content-Type: %@\r\n\r\n", headers[@"content-type"]];
NSLog(@"%@",headers[@"content-type"]);
[body appendFormat:@"%@", [NSString stringWithContentsOfFile:param[@"fileName"] encoding:NSISOLatin1StringEncoding error:&error]];
if (error) {
NSLog(@"%@", error);
}
} else {
[body appendFormat:@"Content-Disposition:form-data; name=\"%@\"\r\n\r\n", param[@"name"]];
[body appendFormat:@"%@", param[@"value"]];
}
NSLog(@"Body-----=%@",body);
}
[body stringByAppendingFormat:@"\r\n--%@--\r\n", boundary];
NSData *postData = [body dataUsingEncoding:NSUTF8StringEncoding];
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"http://192.168.1.123/api/v1/sellProperty?api_key=%@&auth_token=%@&device_token=%@",apiKey,check,deviceToken]]
cachePolicy:NSURLRequestUseProtocolCachePolicy
timeoutInterval:10.0];
[request setHTTPMethod:@"POST"];
[request setAllHTTPHeaderFields:headers];
NSLog(@"%@",headers);
[request setHTTPBody:postData];
NSURLSession *session = [NSURLSession sharedSession];
NSURLSessionDataTask *dataTask = [session dataTaskWithRequest:request
completionHandler:^(NSData *data, NSURLResponse *response, NSError *error) {
if (error) {
NSLog(@"%@", error);
} else {
NSDictionary *serializedData = [NSJSONSerialization JSONObjectWithData: data options:kNilOptions error:nil];
NSHTTPURLResponse* httpResponse = (NSHTTPURLResponse*)response;
NSLog(@"%@", httpResponse);
NSLog(@"res %@ serializedData %@", response,serializedData);
}
}];
[dataTask resume];
最佳答案
您正在使用stringByAppendingFormat来创建一个新字符串,而不向现有字符串添加任何内容。
关于ios - NSMutableString的appendFormat不能追加多个项,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35869339/
我正在使用仪器来检测一些泄漏,但有一些泄漏我无法解决; NSMutableString *textedetails = [[NSMutableString alloc] init];
是否可以在不删除 @ 的情况下以某种方式执行此操作?它不喜欢@ cJavaScript.AppendFormat(@" function GetNextProductI
当尝试使用 appendFormat 附加到 NSMutableString 时 - 它会添加空格。 NSM 只是一个 NSMutableString,att_1_variable 和 att_2_v
我的 C# 应用程序中有一个 StringBuilder 实例,其中我希望根据上下文用不同数量的空格填充某些行。我的用法很简单: StringBuilder MyStringBuilder = new
我在这个site 上看到过说明 AppendFormat 用法的 StringBuilder 代码示例: using System; using System.Text; class Program
我正在尝试使用 StringBuilders AppendFormat 方法创建一个包含数据的表。我希望第二列和第三列中的文本左对齐。 这是我在谷歌上找到的一个例子: http://www.cshar
我能做到: myStringBuilder.AppendFormat("hello {0}", "world"); 但是我做不到: myStringBuilder.AppendFormatLine("
我想在字符串生成器 AppendFormat 中有一个简短的 if ,这样当数量不相同时我可以将两种不同的颜色添加到 td。 这就是我的尝试: foreach (var item in dataObj
我正在尝试使用字符串生成器和附加格式来构建一些 html。如何在不出现以下错误的情况下使用逐字字符串文字和附加格式:“索引(从零开始)必须大于或等于零且小于参数列表的大小。” 看这个例子: Strin
我一直在创建动态字符串以 append 到 StringBuilder,如下所示: StringBuilder sb = new StringBuilder(); string bla = "bla"
这个问题在这里已经有了答案: String.Format exception when format string contains "{" (5 个答案) Escape curly brace '
我目前正在做一个几年前写的项目。 我遇到了这一行: stringBuilder.AppendFormat("{0}", value); 据我所知,它正在“格式化”这一事实没有任何区别。没有插入其他字符
鉴于此: NSString *innerXml = @"somevalue"; NSMutableString *xml = [[NSMutableString alloc] init]; 哪个更快?
我正在将 C# 代码转换为 Java,我遇到了这一行(其中 i 是一个 int)。 sb.AppendFormat("\\u{0:X04}", i); 据我所知,Java 在其 StringBuild
我对 StringBuilder 类的 AppendFormat 方法有疑问。我正在创建表格并在字符串生成器对象中附加数据以将其作为邮件发送,但是当我看到我发送的邮件时,它看起来不像表格,它的标题和相
我想使用 appendFormat 将字符串附加到 NSMutableString,插入空格以获得我的字符串的最小长度。 在 objective-c 中,我只是使用 [text.mutableStri
我想知道 StringBuilder,我有一个问题希望社区能够解释。 让我们忘掉代码的可读性,哪些是更快,为什么? StringBuilder.Append: StringBuilder sb = n
我有一个浮点值,我想以格式字符串显示它,如果它对应于 int,则显示整数,如果不对应,则显示一位小数。 像这样: 3.1 3 2.9 2.8 现在我陷入了这个概念,我会做类似的事情: float my
最近的 question came up关于使用 String.Format()。我的部分回答包括使用 StringBuilder.AppendLine(string.Format(...)) 的建议
我是一名优秀的程序员,十分优秀!