Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Parsing a HttpResponse (C++)

Posted on 2010-08-24
3
Medium Priority
?
793 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 2000 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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…

688 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