post请求传xml参数(KissXML 生成xml文件)

最近开发中遇到一个需求,在post请求中,需要传递xml的参数!瞬间感觉不太好了,常规来说都是上传json的, 无奈也只能按照接口文档来做了!

查阅大量资料,KissXML 这个开源框架可以完美解决该问题, 下面粘出实现代码:

- (void)getSkuXmlWithVArray:(NSMutableArray*)vArray pArray:(NSMutableArray*)pArray

{

DDXMLElement *AttributesElement = [DDXMLElement elementWithName:@"Attributes"];for(NSIntegeri =0; i < pArray.count; i++) {

DDXMLElement *ProductAttributeElement = [DDXMLElement elementWithName:@"ProductAttribute"];

[ProductAttributeElement addAttribute:[DDXMLNode attributeWithName:@"ID"stringValue:pArray[i]]];

DDXMLElement *ProductAttributeValueElement = [DDXMLElement elementWithName:@"ProductAttributeValue"];

DDXMLElement *ValueElement = [DDXMLElement elementWithName:@"Value"stringValue:vArray[i]];

[AttributesElement addChild:ProductAttributeElement];

[ProductAttributeElement addChild:ProductAttributeValueElement];

[ProductAttributeValueElement addChild:ValueElement];

}NSLog(@"%@", [AttributesElement XMLString]);

_attributesXml = [AttributesElement XMLString];

}

结果如下:


只需将其转化为字符串, 作为参数即可进行post请求!

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

友情链接更多精彩内容