I am currently trying to port a .Net app to Objective C and Cocoa. I know the basics and have had little trouble with most things. But I'm having trouble retrieving data from the Web.
In C# I would use POST and GET to retrieve information from a server as such
byte[] buffer = Encoding.ASCII.GetBytes("someData");
HttpWebRequest request = (HttpWebRequest)WebRequest.Create("url");
request.Method = "POST";
request.ContentType = "application/x-www-form-urlencoded";
request.ContentLength = buffer.Length;
Stream postData = request.GetRequestStream();
postData.Write(buffer, 0, buffer.Length);
postData.Close();
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
StreamReader reader = new StreamReader(response.GetResponseStream());
while (!reader.EndOfStream)
{
String data = read.ReadLine();
//Do something such as an update on each line read in
}
reader.Close();
response.Close();
but I'm not having much luck finding a Cocoa equivelant. I have seen the use of things such as NSUrlDownload but all the examples I can find always show the download of the data as a single blocking function call. Where what I need is to be able to update things as I recieve data, not just wait for it all to arrive then deal with it. And ideally I would be able to deal with different types of data such as text or binary, so I need something similar to a stream that I can pass to a parser of some kind.
So my question is what is the equivelant of the C# code above?