Friday, July 15, 2011

Send Web Request & XML Parsing

Hello all ,

Here is a complete procedure to send an HTTP web request and parse an XML response returned from the server.

To Do this you must relate your webserver address under remote settings. To do this follow the following steps:

1) Goto Setup under your Name

2) On left pane you can see Administration Setup. Click on Remote Site Settings


3) Click on New Remote Site and register the url


Now you can make requests.

Send Request: In this method i have also used a Method to do encoding

EncodingUtil.urlEncode('varible whose value you wish to encode','Encoding Method').
sig is just a variable that i wish to encode and append in the url.



Parsing: We are using DOM Parser here.It analyses the root elements, walks through each child element and fetches the values.








Enjoy hope it helps in Salesforce
:)

1 comment:

  1. I am getting response from external service in html format. I want to parse it. I tried using 'regex'. but it won't be much helpful as html is context free language.Is there any other way ?

    ReplyDelete