I am trying to upload an image to a server with multipart form data. I was trying it with NSURLConnection and NSMutableURLRequest. But I couldn't get it work. Then I came across ASIHTTPRequest and its support for multipart form requests. But I understand that it is no longer being maintained. Does anyone know of a similar library that I can use?
You can start using AFNetworking. It's an awesome Library :
https://github.com/AFNetworking/AFNetworking
Related
I am a beginner to ios development.
Can anyone tell me how to send data to server in xcode?
I have a requirement where I need to send device information to a server.
You need to first work out what kind of API the server you're talking to has exposed
Most modern web applications expose a Rest API (although I can only speculate as to what the server you mention is exposing). If Rest, then a good starting point should you not wish to write your own network layer is to use Restkit: https://github.com/RestKit/RestKit
If not Rest, then you need information on what the backend API is, and then go from there...
In it's most basic format you'll need to look at using NSURLRequest and NSURLConnection
NSURLRequest : Post data and read the posted page
http://codewithchris.com/tutorial-how-to-use-ios-nsurlconnection-by-example/
I need to upload a file to a server and the request has to specify some form parameters. How can I do this with the NSURLSessionUploadTask? In other words, how can I send a multipart POST request.
cheers
When using NSURLSessionUploadTask, you don't call setHTTPBody on the NSMutableURLRequest (like we used to do with NSURLConnection), but rather you include this in the NSData or file passed to the NSURLSession method, uploadTaskWithRequest (or in the stream we supply for uploadTaskWithStreamedRequest).
In terms of creating the body of the request, itself, you have to do this yourself. Obviously, a framework like AFNetworking can greatly simplify this process.
https://github.com/pyke369/PKMultipartInputStream
This library can generate the multipart request pretty well.
Has anyone managed to get Server-Sent-Events (SSE) working nicely through AFNetworking? I know AFURLConnectionOperation has an inputStream property I can attach to, but the architecture of AFNetworking seems to be oriented around receiving a response, so I'm not sure what the best way to go about it would be.
Any on how to structure such a program would be appreciated. I'm also open to other iOS libraries, if they provide cleaner solutions.
AFRocketClient (built on top of AFNetworking 2.0) contains AFEventSource which is an implementation of the W3C Event Source API.
The combination of Server Side Events and JSON Patch is being referred to as Rocket.
Can ASIHttpRequest call Restful web service ? I knew that Restkit is good at it.
If no,any easy way to convert ?
Can we say that ASIHttpRequest is good at calling soap based web service ?
Thanks for your comments !
ASIHTTPRequest simply does a HTTP request. Nothing more, nothing less. Since REST is also just an HTTP request, you can use ASIHTTPRequest just fine with a restful web service. It doesn't do any parsing of the response, though, so if the response is JSON you still have to parse that yourself.
You can also use ASIHTTPRequest for SOAP but you have to construct the XML by yourself (or using some other library) and parse the XML response by yourself as well. For SOAP you may want to use http://sudzc.com/ instead.
How to have common NSConnection for various data processing from web server in iPhone. If possible can I have code for it
I wrote some blog posts about NSURLConnection.
Using NSURLConnection
Sending POST Data Using NSURLConnection
Hope This Helped. Let me know if you need any more information.