Click here to Skip to main content
15,881,172 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
C#
public static string SendXMLFile(string xmlFilepath, string uri, int timeout)
    {
        HttpWebRequest request = (HttpWebRequest)WebRequest.Create(uri);

        request.KeepAlive = false;
        request.ProtocolVersion = HttpVersion.Version10;
        request.ContentType = "application/xml";
        request.Method = "POST";

        StringBuilder sb = new StringBuilder();
        using (StreamReader sr = new StreamReader(xmlFilepath))
        {
            String line;
            while ((line = sr.ReadLine()) != null)
            {
                sb.AppendLine(line);
            }
            byte[] postBytes = Encoding.UTF8.GetBytes(sb.ToString());

            if (timeout < 0)
            {
                request.ReadWriteTimeout = timeout;
                request.Timeout = timeout;
            }

            request.ContentLength = postBytes.Length;

            try
            {
                Stream requestStream = request.GetRequestStream();

                requestStream.Write(postBytes, 0, postBytes.Length);
                requestStream.Close();


                using (var response = (HttpWebResponse)request.GetResponse())
                {
                    return response.ToString();
                }

            }
            catch (Exception ex)
            {
                //msg(ex.Message);
                request.Abort();
                return string.Empty;
            }
        }
Posted
Comments
ZurdoDev 20-Nov-15 11:09am    
I'd suggest contacting whoever runs the remote server and see if their logs give you more information. Sounds like a mal-formed xml or possibly missing key information they are expecting.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900