0

I'm calling an external site from Visualforce and it's returning me a response as below (i.e. HttpResponse.GetBody() returned sting).

<DtResponse RequestId="" ResultCount="1" ErrorMessage=""> <Result TemporaryKey="**SecretTempKeyValue***==" /> </DtResponse> 

I can read it by using string functions which is not a good method. I need to read this without using string functions. What is the best method to read the Temporary Key field in HTTP Response body?

Any help with a simple code example would be great. Thanks.

  • 1
    If the response is not in specific format then you have to read it through string function. If the response is in JSON or XML, you can use JASON parser or XML parser class. – MIX DML Dec 1 '16 at 3:53
2

You can use getBodyDocument instead, which would look like this:

Dom.Document doc = response.getBodyDocument();
String tempKey = doc.getRootElement()
                  .getChildElement('Result', null)
                  .getAttribute('TemporaryKey', null);

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.