Solved

Parsing a HttpResponse (C++)

Posted on 2010-08-24
3
779 Views
Last Modified: 2012-05-10
Experts,

I'm currently getting a Http response as a binary string and writing it to a log file (below). Instead I'd like to parse it as a string. E.g. if the response contains an XML tag <response>200</response> I'd like to parse that out.

How would I go about doing this?

thanks!

HttpWebResponse^ httpResponse = nullptr;
BinaryReader^ httpResponseStream = nullptr;

                  httpResponse = (HttpWebResponse^)httpRequest->GetResponse();
                  httpResponseStream = gcnew BinaryReader(httpResponse->GetResponseStream(), Encoding::UTF8);
                  array<Byte>^ readData;
                  // Write Response To File
            while (true)
            {
                readData = httpResponseStream->ReadBytes(4096);
                if (readData->Length == 0)
                    break;
                logFile->Write(readData, 0, readData->Length);
            }
0
Comment
Question by:php-newbie
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 16

Accepted Solution

by:
kris_per earned 500 total points
ID: 33514656
You can use StreamReader to get the response as text....

httpResponse = (HttpWebResponse^)httpRequest->GetResponse();

StreamReader^ reader = gcnew StreamReader (httpResponse->GetResponseStream());

string^ textData = reader->ReadToEnd();

// To parse the xml data (to get the value 200 in <response>200</response>)

XmlDocument^ doc = gcnew XmlDocument;
doc->LoadXml( textData );

XmlNode^ root = doc->DocumentElement;
XmlNode^ node = root->SelectSingleNode( "response" );

String^ responseValue = node->InnerText;

Hope this helps.
0
 

Author Closing Comment

by:php-newbie
ID: 33516975
Thanks, awesome!!!
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …
Suggested Courses

752 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question