I need to do a post to a url which need to be authenticated first, in C#, i can do this
HttpWebRequest myRequest = (HttpWebRequest)WebRequest.Create(url);
myRequest.Method = "POST";
myRequest.ContentType = "application/x-www-form-urlencoded";
myRequest.Credentials = new NetworkCredential(username, password);
myRequest.PreAuthenticate = true;
Stream newStream = myRequest.GetRequestStream();
newStream.Close();
// Get response
try
{
HttpWebResponse response = (HttpWebResponse)myRequest.GetResponse();
return response.StatusDescription;
// some other code
}
catch (Exception ex)
{
return ex.Message;
}
how to do this in php?