Hey guys I am trying to send an XML to a URL and I am getting back a 500 error. I am not sure why since this is an external service I am trying to use.
I used the chrome extension DHC - REST/HTTP API Client to test out the url and the XML and it gets a 200 response! When I compare the feeds mine from my .NET project and the google chrome extension one these are the differences.
Google Chrome Extension Feed: 200 response
POST https://togatest.efiletexas.gov/EPayments/Webs/EPayment.aspx HTTP/1.1
Host: togatest.efiletexas.gov
Connection: keep-alive
Content-Length: 328
Origin: chrome-extension://aejoelaoggembcahagimdiliamlcdmfm
User-Agent: Mozilla/5.0 (Windows NT 6.3; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/44.0.2403.89 Safari/537.36
Content-Type: text/plain
Accept: */*
Accept-Encoding: gzip, deflate
Accept-Language: es,en-US;q=0.8,en;q=0.6
Cookie: _ga=GA1.2.1578362496.1438095893; _mkto_trk=id:659-PBW-104&token:_mch-efiletexas.gov-1436559093618-37466; ASP.NET_SessionId=ug3njkuiz23oq255ouwsax3w
<PaymentRequest xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<ClientKey>CJOFSTEXFILE123</ClientKey>
<TransactionID>TESTESTTEST123</TransactionID>
<RedirectURL>https://localhost:44300/efile</RedirectURL>
<Amount>-1</Amount>
<GetToken>1</GetToken>
</PaymentRequest>
My Project Feed: 500 Response
POST https://togatest.efiletexas.gov/EPayments/Webs/EPayment.aspx HTTP/1.1
Content-Type: text/plain
Accept: */*
Host: togatest.efiletexas.gov
Content-Length: 334
Connection: Keep-Alive
<PaymentRequest xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<ClientKey>CJOFSTEXFILE123</ClientKey>
<TransactionID>TESTESTTEST123</TransactionID>
<RedirectURL>https://localhost:44300/efile</RedirectURL>
<Amount>-1</Amount>
<GetToken>1</GetToken>
</PaymentRequest>
For some reason I cant get the page to load I am getting an 500 error. I believe this is due because the content length is different and I dont know why. The XML's are exactly the same but perhaps the chrome extension is doing something different when opening the connection. Any help and explanation would be awesome. If someone can tell me how to manually change the content-length that would be really cool as well.
UPDATE:
Here is the code I am using to serialize my C# object, and open the connection for the URL
PaymentRequest tokenPaymentRequest = new PaymentRequest();
//Here we will set the values of our object
tokenPaymentRequest.ClientKey = "CJOFSTEXFILE123";
tokenPaymentRequest.TransactionID = "TESTESTTEST123";
tokenPaymentRequest.RedirectURL = "https://localhost:44300/efile";
tokenPaymentRequest.Amount = "-1";
tokenPaymentRequest.GetToken = "1";
var doc = new XDocument();
var xmlSerializer = new XmlSerializer(typeof(PaymentRequest));
using (var writer = doc.CreateWriter())
{
xmlSerializer.Serialize(writer, tokenPaymentRequest);
}
string xml = doc.ToString();
HttpWebRequest req = (HttpWebRequest)WebRequest.Create(destinationUrl);
//string s = "id="+Server.UrlEncode(xml);
byte[] requestBytes = System.Text.Encoding.ASCII.GetBytes(xml);
req.Method = "POST";
req.ContentType = "text/plain";
req.Accept = "*/*";
req.ContentLength = requestBytes.Length;
Stream requestStream = req.GetRequestStream();
requestStream.Write(requestBytes, 0, requestBytes.Length);
requestStream.Close();
HttpWebResponse res = (HttpWebResponse)req.GetResponse();
StreamReader sr = new StreamReader(res.GetResponseStream(), System.Text.Encoding.Default);
string backstr = sr.ReadToEnd();
sr.Close();
res.Close();
return string.Empty;