Click here to Skip to main content
15,069,297 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hi Friends,
In my web project, I am using http request and response for access https payment site.
but when i call getresponse() function, it return "Precondition failed (412)" error.

HttpWebRequest paymentRequest = (HttpWebRequest)WebRequest.Create("https://xxxxxx/authorize");
                Uri uri = new Uri("https://xxxxxx/authorize");
                NetworkCredential netCredential = new NetworkCredential("XXXXXXXXX", "XXXXXXXXX");
                paymentRequest.Credentials = netCredential.GetCredential(uri, "Basic");
                paymentRequest.PreAuthenticate = true;

                byte[] Data = System.Text.Encoding.ASCII.GetBytes(sXMLTemplate);
                paymentRequest.Method = "POST";
                paymentRequest.Headers.Add("MIME-Version", "1.0");
                paymentRequest.Headers.Add("Request-number", "1");
                paymentRequest.Headers.Add("Document-type", "Request");
                paymentRequest.Headers.Add("Content-transfer-encoding", "application/xml");
                paymentRequest.ContentType = "application/xml";
                paymentRequest.ContentLength = Data.Length;
                paymentRequest.KeepAlive = true;

                Stream streamWriter = paymentRequest.GetRequestStream();
                streamWriter.Write(Data, 0, Data.Length);

                HttpWebResponse paymentResponse = (HttpWebResponse)paymentRequest.GetResponse();
                Stream responseStream = paymentResponse.GetResponseStream();
                reader = new XmlTextReader(responseStream);

how to fix this error?

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