Hi,
I have an iPhone app in which the user downloads new data once a week from external server. The company that provides the data recently changed the authentication method to POST.
So far I was using NSUrlConnection and NSUrlReqeust, and the delegate method didReceiveAuthenticationChallenge to enter the user name and password and then download the file (Using NSData to write the file).
However, now that they changed the authentication method I can't figure out what classes to use to download the files. They gave the following example in C#:
I cant figure out how to rewrite this code in objective C. Can someone help?
Thanks.
Roei
I have an iPhone app in which the user downloads new data once a week from external server. The company that provides the data recently changed the authentication method to POST.
So far I was using NSUrlConnection and NSUrlReqeust, and the delegate method didReceiveAuthenticationChallenge to enter the user name and password and then download the file (Using NSData to write the file).
However, now that they changed the authentication method I can't figure out what classes to use to download the files. They gave the following example in C#:
Code:
using System;
using System.Collections.Generic;
using System.Text;
using System.IO;
namespace TechnetSamples
{
class Program
{
static void Main(string[] args)
{
string URL = "FILE_URL_PATH";
System.Net.WebRequest webRequest = System.Net.WebRequest.Create(URL);
webRequest.Method = "POST";
webRequest.ContentType = "application/x-www-form-urlencoded";
Stream reqStream = webRequest.GetRequestStream();
string postData = "username=YourUser&password=YourPassword";
byte[] postArray = Encoding.ASCII.GetBytes(postData);
reqStream.Write(postArray, 0, postArray.Length);
reqStream.Close();
StreamReader sr = new StreamReader(webRequest.GetResponse().GetResponseStream());
string Result = sr.ReadToEnd();
using (TextWriter tw = new StreamWriter("c:\\result.csv", true))
{
tw.Write(Result);
}
}
}
}
I cant figure out how to rewrite this code in objective C. Can someone help?
Thanks.
Roei