title: Salesforce error while makin a call to a web service api
body: <p>I get the following error when I call the function add()
  <code>You have uncommitted work pending. Please commit or rollback before calling out</code></p>
  
  <p>I call the <code>getItems()</code> to populate the drop down and then the <code>add</code> function to insert the selected item from the drop down</p>
  
  <pre><code> public PageReference add() {
                insert technology;
                return null;
              }
  
  public List&lt;SelectOption&gt; getItems() {
      List&lt;SelectOption&gt; options = new List&lt;SelectOption&gt;();
      List&lt;Technology__c&gt; AddedT=[SELECT Name FROM Technology__c];
      HttpRequest req = new HttpRequest(); 
      req.setMethod('GET');
      req.setEndpoint('http://submit.toolsberry.com/sfdc/technologies');
      Http http = new Http();
      HTTPResponse res = http.send(req);  
      String response=res.getBody();
      XmlStreamReader reader = new XmlStreamReader(response);
       List&lt;String&gt; AllTech = new List&lt;String&gt;();
       while(reader.hasNext()) {    
       if (reader.getEventType() == XmlTag.START_ELEMENT) {
          if ('string' == reader.getLocalName()) {
      while(reader.hasNext()) {
       if (reader.getEventType() == XmlTag.END_ELEMENT) {
          break;
       } else if (reader.getEventType() == XmlTag.CHARACTERS) {
          String tname = reader.getText();
          AllTech.add(tname);
      }
      reader.next();
   }
          }
       }
      reader.next();
   }
  }
  </code></pre>