narzedziowniawarszawska
New Member
I am trying to send some data to a web service using a form with POST method, to which it responds with an XML page. I have the POST part working with a simple form and submit in my View. However, I am not sure how to handle the response from here, so I am trying to move it all into the controller (seems like it should be there anyway). So the theory is to have the user click a button which sends model data to the controller. In the controller i am trying to put together a webrequest, looks like this:\[code\] [HttpPost] public ActionResult SubmitToCris(NewApplicantViewModel model) { string serviceURL = "https://www.blahblah.com/XMLServer/XMLServer.cgi"; string postData = "http://stackoverflow.com/questions/13827489/MaxRecords=0&UserID=skapi&Password=sk12024&Version=2.0&RequestType=searchName&FirstName=Nathan" + "&LastName=Smith&DOB=1984/2/2"; WebRequest request = WebRequest.Create(serviceURL); request.Method = "POST"; byte[] byteArray = Encoding.UTF8.GetBytes(postData); request.ContentLength = byteArray.Length; Stream dataStream = request.GetRequestStream(); dataStream.Write(byteArray, 0, byteArray.Length); dataStream.Close(); WebResponse response = request.GetResponse(); dataStream = response.GetResponseStream(); StreamReader reader = new StreamReader(dataStream); return View(); }\[/code\]I don't seem to be getting a response so I dug in an found a "stream does not support seek operations". Looks like this is caused by an inability read the length of the byte array. I will fix it by looping through.So what I am looking for right now is, is this even the correct way to go? I have been researching this all morning and have come up with multiple ways of doing this, I went with this one because it seemed the most direct approach.Anywho, if I could get an MVC or ASP specific example or tutorial on how this is all supposed to work, that would be great. Thanks.-------EDIT-------------Changed the postData variable.Here is the response I receive from the other companies web server after posting the data:\[code\]<?xml version="1.0" encoding="UTF-8"?> <HistoryResponse> <ResponseType>resultsList</ResponseType> <Matches>0</Matches> <SessionID>75803234r23df3de</SessionID> <RecStart>0</RecStart> <ClientCode></ClientCode> <Results></Results></HistoryResponse>\[/code\]