Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4345124
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T11:59:32+00:00 2026-05-21T11:59:32+00:00

I am sending a HTTP GET request to the web service of an external

  • 0

I am sending a HTTP GET request to the web service of an external company. This is coming back fine, but I am running into problems with the interpretation of what comes back. The response is sent in XML. I have tried to use SimpleXML (which I admit, I am not familiar with) and cannot figure it out. What I need to do is assign something received in the XML to a PHP variable and then echo it. The variable I need to assign is “SessionToken” to $sessionid. How do I do this?

Here is an example of my code:


error_reporting(E_ALL);

$request =  'http://ws.examplesite.com/test/test.asmx/TestFunction?Packet=<Packet><Email>test@example.com</Email><Password>testpassword</Password></Packet>';

$session = curl_init($request);

curl_setopt($session, CURLOPT_HEADER, true);

curl_setopt($session, CURLOPT_RETURNTRANSFER, true);

$response = curl_exec($session);

curl_close($session);

$status_code = array();
preg_match('/\d\d\d/', $response, $status_code);

switch( $status_code[0] ) {
    case 200:
        break;
    case 503:
        die('Your call to Web Services failed and returned an HTTP status of 503. That means: Service unavailable. An internal problem prevented us from returning data to you.');
        break;
    case 403:
        die('Your call to Web Services failed and returned an HTTP status of 403. That means: Forbidden. You do not have permission to access this resource, or are over your rate limit.');
        break;
    case 400:
        die('Your call to Web Services failed and returned an HTTP status of 400. That means:  Bad request. The parameters passed to the service did not match as expected. The exact error is returned in the XML response.');
        break;
    default:
        die('Your call to Web Services returned an unexpected HTTP status of:' . $status_code[0]);
}


if (!($xml = strstr($response, '<?xml'))) {
    $xml = null;
}

echo $xml;

Here is an example of the response:


<?xml version="1.0" encoding="utf-8"?>
<string xmlns="http://ws.example.com/resumes/">
  <Packet>
    <Errors />
    <SessionToken>1234567890</SessionToken>
  </Packet>
</string>

How can I extract variables from XML and assign them to PHP variable?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-21T11:59:33+00:00Added an answer on May 21, 2026 at 11:59 am

    You can use the php xpath() function.

    In you example I would do something like this

    $xml = simplexml_load_string($response);
    $xpathresult = $xml->xpath("//SessionToken");
    list(,$sessionToken) = each($xpathresult)
    if($sessionToken)
    {
      //Code here
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am sending password text to the http service request object.like <request><password>pass.text</password></request> now this
I am sending HTTP GET request and receiving data here: ssize_t numBytes = recvfrom(sock,
I have this simple code where I am sending http request and reading all
I am sending a http request and a cookie is send back. I can
I have a RESTful web service running on Jersey (GlassFish 3.1.1). This one's a
I have a problem with sending POST http request. It stops on (HttpWebResponse)request.GetResponse() and
I got some sample code from the net here: http://www.javadb.com/sending-a-post-request-with-parameters-from-a-java-class That works fine. It
I'm dynamically building a CAML string then sending a request to SharePoint web services
I'm using a Web Service that has a endpoint of http://api.domain_a.com/ and using Visual
I have a web service in the form `http://....../methodName It returns a jsonp result

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.