SitePoint Sponsor

User Tag List

Results 1 to 2 of 2

Hybrid View

  1. #1
    SitePoint Member
    Join Date
    Aug 2013
    Posts
    4
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Question How to cross domain call a xml web service?

    I am a new developer and I have this simple xml web service to call: http://54.225.189.16/UACServices/GSa...p=validateUser

    The problem I have is that it is on another domain so I have to find a way to work it out, could anyone help?

  2. #2
    Barefoot on the Moon! silver trophy Force Flow's Avatar
    Join Date
    Jul 2003
    Location
    Northeastern USA
    Posts
    4,606
    Mentioned
    56 Post(s)
    Tagged
    1 Thread(s)
    You'll need to call it with cURL.

    I used this function when I encountered a similar situation a couple years back.

    PHP Code:
    /**
         * load XML file using cURL from outside URL
         * if cURL is not available, this defaults to using simplexml_load_file()
         * @param string $url
         */
        
    function simplexml_load_file_curl($url) {
            
    $xml="";
        
            if(
    in_array('curl'get_loaded_extensions())){
                
    $ch curl_init($url);
                
    curl_setopt($chCURLOPT_RETURNTRANSFER1);
                
    $xml simplexml_load_string(curl_exec($ch));
                
    curl_close($ch);
            }
            else{
                
    $xml simplexml_load_file($url);
            }
        
            return 
    $xml;
        }


    $xml simplexml_load_file_curl('http://example.org/xml-file-url.xml'); 
    Then just treat it as a SimpleXMLElement: http://www.php.net/manual/en/class.simplexmlelement.php

    http://php.net/manual/en/book.simplexml.php

    http://www.php.net/manual/en/simplex...ples-basic.php
    Visit The Blog | Follow On Twitter
    301tool 1.1.5 - URL redirector & shortener (PHP/MySQL)
    Can be hosted on and utilize your own domain


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •