public TrackingData MakeRequest(string serverUrl, AccessRequest ar) { string postString; byte[] postData; HttpWebRequest req; Stream requestStream; string responseXml; WebResponse response; Stream responseStream; StreamReader sr; postString = ar.Serialize(); postString += Serialize(); postData = System.Text.Encoding.UTF8.GetBytes(postString); //Set up the request req = (HttpWebRequest)WebRequest.Create("https://www.ups.com/ups.app/xml/Track"); req.Method = "POST"; req.ContentType="application/x-www-form-urlencoded"; req.ContentLength = postData.Length; requestStream = req.GetRequestStream(); // Send the data. requestStream.Write(postData, 0, postData.Length); requestStream.Close(); //Get the response response = req.GetResponse(); responseStream = response.GetResponseStream(); sr = new StreamReader(responseStream); responseXml = sr.ReadToEnd(); return TrackingResponse.GetCommonTrackingData(responseXml); }
public void Serialize() { var ar = new AccessRequest("abc", "def", "ghi"); var serialized = ar.Serialize(); const string expected = "<?xml version=\"1.0\" encoding=\"utf-16\"?>\r\n<AccessRequest xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\">\r\n <AccessLicenseNumber>abc</AccessLicenseNumber>\r\n <UserId>def</UserId>\r\n <Password>ghi</Password>\r\n</AccessRequest>"; Assert.AreEqual(expected, serialized); }
public TrackingData MakeRequest(AccessRequest ar) { return MakeRequest(PRODUCTION_URL, ar); }