Solved

PHP get data from url (XML) with special charachters in password

Posted on 2014-11-04
10
184 Views
Last Modified: 2014-11-08
Hello

I have this in php:

$url = 'http://agent.datasource.com/webservice/service.asmx/GetProperty?username=edxx7f14&password=#4322f$&Account=v3ced4511';
$xml = my_curl($url);
$obj = SimpleXML_Load_String($xml);

I  believe it fails because of the "#" in the password.  The url below works in a browser address bar when I change the # to %23.  How can I work around this in my code if I can't get the password changed.

http://agent.datasource.com/webservice/service.asmx/GetProperty?username=edxx7f14&password=%234322f$&Account=v3cxx4511

Thank you very much for your help.

Sky
0
Comment
Question by:Schuyler Kuhl
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 4
10 Comments
 
LVL 57

Expert Comment

by:Julian Hansen
ID: 40421959
And if you change the $url to be the same as the second URL?
0
 
LVL 110

Expert Comment

by:Ray Paseur
ID: 40422024

Server not found

What is the real URL?  If you tell us that we can show you a tested and working code example.
0
 

Author Comment

by:Schuyler Kuhl
ID: 40422060
0
How Do You Stack Up Against Your Peers?

With today’s modern enterprise so dependent on digital infrastructures, the impact of major incidents has increased dramatically. Grab the report now to gain insight into how your organization ranks against your peers and learn best-in-class strategies to resolve incidents.

 
LVL 110

Expert Comment

by:Ray Paseur
ID: 40422112
Here's what I'm seeing: Missing parameter: barefootAccount.

Here's the URL I'm using:
<?php // demo/temp_skykuhl.php
error_reporting(E_ALL);
echo '<pre>';

// READ THE URL
$url = 'http://agent.barefoot.com/barefootwebservice/barefootservice.asmx/GetProperty?username=ed007f14&password=#4311f$&barefootAccount=v3ced4311';

/** SOME WAYS OF LOOKING AT THE DATA
echo PHP_EOL . $url;
echo PHP_EOL . htmlentities($url);
echo PHP_EOL . urlencode($url);
echo PHP_EOL;
*/

$htm = file_get_contents($url);

echo htmlentities($htm);

Open in new window

I'll try a few things and see if I can help clear this up.  The key concepts in play seem to be related to urlencode()
0
 
LVL 110

Expert Comment

by:Ray Paseur
ID: 40422140
I think it was the un-urlencode() dollar sign that was tripping things up.
http://iconoun.com/demo/temp_skykuhl.php

<?php // demo/temp_skykuhl.php
error_reporting(E_ALL);
echo '<pre>';

// THE URL PATH TO THE API
$url = 'http://agent.barefoot.com/barefootwebservice/barefootservice.asmx/GetProperty';

// THE ARGUMENTS
$args = array
( 'barefootAccount' => 'v3ced4311'
, 'username'        => 'ed007f14'
, 'password'        => '#4311f$'
)
;

// ATTACH THE ARGUMENTS
$url .= '?';
foreach ($args as $key => $str)
{
    $url .= $key . '=' . urlencode($str) . '&';
}
$url = rtrim($url, '&');

// SHOW THE URL
echo PHP_EOL . htmlentities($url);
echo PHP_EOL;

// AND TRY TO READ
$htm = file_get_contents($url);
$obj = SimpleXML_Load_String($htm);
var_dump($obj);

Open in new window

0
 
LVL 110

Accepted Solution

by:
Ray Paseur earned 500 total points
ID: 40422151
This makes more sense - the return values from the API are in kind of a strangely nested format.

<?php // demo/temp_skykuhl.php
error_reporting(E_ALL);
echo '<pre>';

// THE URL PATH TO THE API
$url = 'http://agent.barefoot.com/barefootwebservice/barefootservice.asmx/GetProperty';

// THE ARGUMENTS
$args = array
( 'barefootAccount' => 'v3ced4311'
, 'username'        => 'ed007f14'
, 'password'        => '#4311f$'
)
;

// ATTACH THE ARGUMENTS
$url .= '?';
foreach ($args as $key => $str)
{
    $url .= $key . '=' . urlencode($str) . '&';
}
$url = rtrim($url, '&');

// SHOW THE URL
echo PHP_EOL . htmlentities($url);
echo PHP_EOL;

// AND TRY TO READ (IT IS A WIERD FORMAT)
$htm = file_get_contents($url);
$obj = SimpleXML_Load_String($htm);
$obj = SimpleXML_Load_String($obj[0]);
var_dump($obj);

Open in new window

0
 

Author Comment

by:Schuyler Kuhl
ID: 40423852
Thank you very much.  I am trying these suggestions now.

Best regards,

Sky
0
 

Author Comment

by:Schuyler Kuhl
ID: 40423877
Dear Ray,

Thank you very much.  I just tested your last post.  It works well.  Thank you very much.

I am going to see about integrating it now.  

Ray, you have helped me many times in the past.  I greatly appreciate your knowledge and generosity.

Best regards,

Sky
0
 
LVL 110

Expert Comment

by:Ray Paseur
ID: 40423935
Thanks for your kind words, Sky!  Best of luck with your project, ~Ray
0

Featured Post

Space-Age Communications Transitions to DevOps

ViaSat, a global provider of satellite and wireless communications, securely connects businesses, governments, and organizations to the Internet. Learn how ViaSat’s Network Solutions Engineer, drove the transition from a traditional network support to a DevOps-centric model.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction This article is intended for those who are new to PHP error handling (https://www.experts-exchange.com/articles/11769/And-by-the-way-I-am-New-to-PHP.html).  It addresses one of the most common problems that plague beginning PHP develop…
This article discusses how to implement server side field validation and display customized error messages to the client.
The viewer will learn how to count occurrences of each item in an array.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

734 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question