C#: HTTPWebResponse using application/x-www-form-urlencoded

Posted by CSharpened on Stack Overflow See other posts from Stack Overflow or by CSharpened
Published on 2012-11-07T10:40:35Z Indexed on 2012/11/07 11:00 UTC
Read the original article Hit count: 192

Filed under:
|

So I sent an HTTPWebRequest using application/x-www-form-urlencoded as my content type. I assume that this means the reponse will be returned in a similar type? (EDIT: Have now been told this isn't the case)

My question is this. How do I access the different key/value pairs returned in the response. My code so far looks like this. I can of course read the string but surely there is a better way to access the data other than ripping the string apart.

    HttpWebResponse response = SendPOSTRequest("https://site/page?Service=foo", content.ToString(), "", "", true);

    string responseCode = response.StatusCode.ToString();
    string responseStatusDescription = response.StatusDescription;

    StreamReader sr = new StreamReader(response.GetResponseStream());

    string result = sr.ReadToEnd();

I tried using XML/linq to read the elements into an XDocument but of course it is not being returned in XML form.

Assume I have 3 or 4 different pieces of information in there how could I read them out?

EDIT: I have just checked and the data is being returned as text/plain. How can this be processed easily?

EDIT: The response string once retrieved via a streamreader is:

VPSProtocol=2.23
Status=OK
StatusDetail=Server transaction registered successfully.
VPSTxId={FDC93F3D-FC64-400D-875F-0B7E855AD81F}
SecurityKey=*****
NextURL=https://foo.com/PaymentPage.asp?TransactionID={875F-0B7E855AD81F}

© Stack Overflow or respective owner

Related posts about c#

Related posts about httpwebresponse