iPhone UIImage upload to web service

余生长醉 提交于 2019-11-29 02:37:06

It fails because the %@ format specifier takes an object and calls -(NSString*)description to turn it into a string. -[NSData description] returns something like @"<31 32 33 65 66 67>" for (ASCII) "123abc", hence you're submitting <31 32 33 65 66 67> which obviously isn't valid XML. Don't glue strings together (it'll be vulnerable to XML injection, among other things).

I would drop SOAP and just use

[req addValue:@"image/jpeg" forHTTPHeaderField:@"Content-Type"];
[req setHTTPBody:imgData]

If you want to use SOAP, then there's probably an Objective-C SOAP library which will do packaging for you. Failing that, you can manually specify xs:base64Binary (I think) and use base64-encoded data. Neither of these is ideal, since it makes the data 33% larger. If you're unlucky, a SOAP library will make it 20000% larger!

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!