public static UtcResponse PutUtcRequest(UtcPutRequest putRequest) { UtcResponse retVal = new UtcResponse(); string url = putRequest.Url + putRequest.Action; HttpWebRequest myReq = (HttpWebRequest)WebRequest.Create(url); //CredentialCache myCache = new CredentialCache(); //myCache.Add(new Uri(url), "Basic", new NetworkCredential(ApiToken, "")); //myReq.Credentials = myCache; // byte[] byteArray = Encoding.UTF8.GetBytes(putRequest.XmlDoc.InnerXml); byte[] byteArray = Encoding.UTF8.GetBytes(putRequest.XmlDoc); myReq.ContentType = "application/xml"; myReq.ContentLength = byteArray.Length; myReq.Method = "POST"; Stream dataStream = myReq.GetRequestStream(); dataStream.Write(byteArray, 0, byteArray.Length); dataStream.Close(); try { HttpWebResponse wr = (HttpWebResponse)myReq.GetResponse(); retVal.StatusCode = (int)wr.StatusCode; Stream receiveStream = wr.GetResponseStream(); StreamReader reader = new StreamReader(receiveStream, Encoding.UTF8); retVal.Xml = reader.ReadToEnd(); retVal.Success = true; } catch (WebException ex) { HttpWebResponse exResponse = (HttpWebResponse)ex.Response; retVal.StatusCode = (int)exResponse.StatusCode; retVal.ErrorMessage = ex.Message; } return(retVal); }
public static UtcResponse PutUtcRequest(UtcPutRequest putRequest) { UtcResponse retVal = new UtcResponse(); string url = putRequest.Url + putRequest.Action; HttpWebRequest myReq = (HttpWebRequest)WebRequest.Create(url); //CredentialCache myCache = new CredentialCache(); //myCache.Add(new Uri(url), "Basic", new NetworkCredential(ApiToken, "")); //myReq.Credentials = myCache; // byte[] byteArray = Encoding.UTF8.GetBytes(putRequest.XmlDoc.InnerXml); byte[] byteArray = Encoding.UTF8.GetBytes(putRequest.XmlDoc); myReq.ContentType = "application/xml"; myReq.ContentLength = byteArray.Length; myReq.Method = "POST"; Stream dataStream = myReq.GetRequestStream(); dataStream.Write(byteArray, 0, byteArray.Length); dataStream.Close(); try { HttpWebResponse wr = (HttpWebResponse)myReq.GetResponse(); retVal.StatusCode = (int)wr.StatusCode; Stream receiveStream = wr.GetResponseStream(); StreamReader reader = new StreamReader(receiveStream, Encoding.UTF8); retVal.Xml = reader.ReadToEnd(); retVal.Success = true; } catch (WebException ex) { HttpWebResponse exResponse = (HttpWebResponse)ex.Response; retVal.StatusCode = (int)exResponse.StatusCode; retVal.ErrorMessage = ex.Message; } return retVal; }