objc POST file and string parameters - ios

I am trying to POST a file, and some string params to a .ashx page on my server from my iPad app using objc.
I have found lots of tutorials on how to post a file using objc, and I already have code to post strings. But I cant work out how to combine the two, so I can send multiple values in a single POST?
Could anyone help me out with an example or two? I am trying to avoid using 3rd party frameworks, so something using NSURLRequest would be preferred.
Thanks,
Mike

You need to use a multipart submission, with boundary strings, etc. Here's some helper code: https://github.com/Goles/SimpleHttpRequest from the answer to this question: Sending multipart POST from iOS and reading parameters in PHP $_POST?

Related

Get data from server in iOS

I have a script that takes hours and outputs if it is open or closed and I want to run this on my server, and then from my iOS app get if a certain place is open or closed. And I was wondering how I could do this without generating an JSON file and then parsing that as I would to frequently re-generate the file as the things change from open to closed and such. So is there a way I could make a call to the server and just get the data that I want?
Im not entirely sure whether you are asking specifically for an iOS framework for requests and responses or server side. So I figure I will try to answer both. Here are some swift projects you might be interested in. I'm not incredibly familiar with objective c yet but these resources might prove useful.
Alamofire
This will help you send and receive http requests.
Swifty JSON
This will help with JSON parsing
However if your question is more regarding server side issues. You could look into a REST api and that way you could only request certain entities that you are interested in instead of just sending back the entire batch of information with all of your data, and searching through it on the iOS device.
Hopefully this is somewhat helpful.
If you are only planning on GET-ing some content from the web you can use the NSURL class. NSURL *lru = [NSURL URLWithString:#"http:mywebserver.com"] and then create a new string object from the url with [NSString stringWithContentsOfURL:lru], or any data you would like. If you are trying to hold a session or having more control over the request, I would suggest looking into the NSURLSession class.

Using Car2go Api for iOS app

Hi I am trying to get the list of all car2go cars and use it for a test application, the only problem is I do not know how to get the information. I have gotten a consumer key and secret key but the problem is I am unsure how to get the file using the api and then once I get the file I don't know how I would read it since it is using xml.
The response from the html is on this site
http://code.google.com/p/car2go/wiki/vehicles_v2_1
once I get the file I don't know how I would read it since it is using xml
You'll need to parse the response to extract the data you want. There are a number of ways to do that. For example, you could use NSXMLParser (which is included in Cocoa Touch), or you could use the TouchXML library, or you could use libxml.

JSON GET and POST

I am learning iOS app development.
I have JSON data coming from one of the sites in the form of Dictionary within an Array and within that Dictionary I have another Array and that contains another Dictionary.
for ex ,
Now I want to deserialize it and use it in my iOS app and also I have to post some data like a comment back to the server.The comment by teacher will be a POST to the server.
I hope the question makes sense.
I am stuck on how to deserialize this and use POST to server.
Any help is appreciated. Thanks in advance.
There are a couple of parts to your question:
1) To get the JSON data into a format which can easily be manipulated by your program, it's easiest to take an existing open-source JSON parser library and integrate it into your app. I like SBJSON. If you go to that site, it has instructions on including and using the library in your project.
2) To post a reply to the server, you need to know what format it expects the data in. Is your app interacting with an existing website (where a user could go to a page and fill out a form), or is it talking to an API?

Example on using AFNetworking to post XML?

As a followup to this question, I cannot get this to work so I need to take a step back I think.
Can someone post some sample code on how to post XML to a rest service WITHOUT using params? Is it even possible? Basically I have an object with several properties, and I convert this to XML and then need to upload it. But it fails if there is an image converted to string in the XML. Without that it works fine.
Even a JSON example would be helpful...
Totally blocked here :P
Use NSMutableURLRequest -setHTTPBody:, and set the Content-Type HTTP header to application/xml.
If you're doing this consistently, you may want to consider subclassing AFHTTPClient to add an XML parameter serialization option.

sending post data from Iphone

I want to send post data from Iphone.
I have to send a dictionary(K-V pairs) with 8 k-v pairs.
What is the best way to post all these 8 K-V pairs from Iphone.
I want that i should pass only Id(one of K-V pair)in the URL & remaining K-V pairs should be sent via post.
if there is something like that??
I wrote a couple blog posts using NSURLConnection. One was specifically for sending POST data. Check them out. You can't send some data with GET and some data with POST. You have to commit to all one way.
Sending POST DATA
Using NSURLConnection
HTH
The HTTP protocol doesn't work like that. Pick POST or GET.
This library makes web requests easy, including file upload: http://allseeing-i.com/ASIHTTPRequest/

Resources