private XDocument SendRequest(XElement request, out string errorMessage) { errorMessage = string.Empty; var requestElement = GetRequestElement(); requestElement.Add(request); XDocument xdocRequest = new XDocument(new XDeclaration("1.0", "UTF-8", "yes"), requestElement); XDocument response = null; byte[] postData = ASCIIEncoding.ASCII.GetBytes(xdocRequest.ToString()); HttpWebRequest webRequest = (HttpWebRequest)HttpWebRequest.Create(ReportingApiUrl()); webRequest.Method = "POST"; webRequest.ContentType = "text/plain"; webRequest.ContentLength = postData.Length; var requestStream = webRequest.GetRequestStream(); requestStream.Write(postData, 0, postData.Length); requestStream.Close(); using (WebResponse webResponse = webRequest.GetResponse()) { var stream = webResponse.GetResponseStream(); using (XmlReader reader = XmlReader.Create(stream)) { response = XDocument.Load(reader); var status = new RequestResponse(response); if (status.Code != "100") { errorMessage = status.Message; response = null; } } } return(response); }
private XDocument SendRequest( XElement request, out string errorMessage ) { errorMessage = string.Empty; var requestElement = GetRequestElement(); requestElement.Add( request ); XDocument xdocRequest = new XDocument( new XDeclaration( "1.0", "UTF-8", "yes" ), requestElement ); XDocument response = null; byte[] postData = ASCIIEncoding.ASCII.GetBytes( xdocRequest.ToString() ); HttpWebRequest webRequest = (HttpWebRequest)HttpWebRequest.Create( ReportingApiUrl() ); webRequest.Method = "POST"; webRequest.ContentType = "text/plain"; webRequest.ContentLength = postData.Length; var requestStream = webRequest.GetRequestStream(); requestStream.Write( postData, 0, postData.Length ); requestStream.Close(); using ( WebResponse webResponse = webRequest.GetResponse() ) { var stream = webResponse.GetResponseStream(); using ( XmlReader reader = XmlReader.Create( stream ) ) { response = XDocument.Load( reader ); var status = new RequestResponse( response ); if ( status.Code != "100" ) { errorMessage = status.Message; response = null; } } } return response; }