server client iphone with json
I am trying to make a server client app for iphone and I am using json. I want to load and store some text and some images to my sql server. I was able to get the text from my server but not the images and I have not figured out how to post things to my server.Am I in the right track here开发者_运维知识库 or should I start using xml. Can anybody help me?
If you are using MSSQLServer then writing sever side web services is pretty trivial. With those you should be able to use JSON or XML without too much trouble (but for JSON you need to set the request types)
[[self theRequest] addValue:@"application/json; charset=utf-8" forHTTPHeaderField:@"Content-type"];
[[self theRequest] setValue:@"json" forHTTPHeaderField:@"dataType"];
Posting text is easy (just use a post request) but to post images you need to simulate multipart forms.
Although there is plenty of code samples around to demonstrate that, I found the ASIHTTP library http://allseeing-i.com/ASIHTTPRequest/ made it all so easy I gave up with my own web service libraries and used that instead.
精彩评论