i got a problem in PHP. i want to get all the bus stations in india. so i have made an xml request and post that xml data to given API URL. but i did not get the result. below is the .net code which is working fine. even i have used the "HttpRequest" method in php, but it gives me an error like "Fatal error: Class 'HttpRequest' not found".
can anybody help me to give me the equivalent code in php or possible ways to get the data..?
thanks in advance.
.net code (working fine)
protected void getBusServices(string journeydate)
{
XmlDocument doc = new XmlDocument();
StringReader stream;
StreamReader reader;
XmlTextReader textreader;
HttpWebRequest req;
HttpWebResponse response;
try
{
string password = "password";
DateTime dt = Convert.ToDateTime(journeydate);
string strJrneyDate = dt.ToString("MM-dd-yyyy");
string strRtDate = dt.AddDays(3).ToString("MM-dd-yyyy");
string url = Bus_Api_Url;
string RequestCommand = "<Command>GET_STATIONS</Command> <Username>username</Username> <Password>password</Password>";
req = (HttpWebRequest)WebRequest.Create(url);
string RequestData = "RequestXML=<?xml version='1.0' encoding='utf-8' ?><BusRequest xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' xmlns:xsd='http://www.w3.org/2001/XMLSchema'>" + RequestCommand + "</BusRequest>";
req.Method = WebRequestMethods.Http.Post;
req.ContentLength = RequestData.Length;
req.ContentType = "application/x-www-form-urlencoded";
using (StreamWriter writer = new StreamWriter(req.GetRequestStream()))
{
writer.Write(RequestData);
}
response = (HttpWebResponse)req.GetResponse();
Stream responsestream = response.GetResponseStream();
reader = new StreamReader(responsestream);
string xmlresponse = reader.ReadToEnd();
stream = new StringReader(xmlresponse);
textreader = new XmlTextReader(stream);
doc.LoadXml(xmlresponse);
DataSet ds = new DataSet();
ds.ReadXml(textreader);
}
catch (Exception ex)
{
EBUtils.Logger.LogError.Publish(ex);
}
finally
{
reader = null;
// stream = null;
reader = null;
response = null;
doc = null;
}
}
}