Solved

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

Posted on 2014-11-04
10
172 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:skykuhl
  • 5
  • 4
10 Comments
 
LVL 51

Expert Comment

by:Julian Hansen
Comment Utility
And if you change the $url to be the same as the second URL?
0
 
LVL 108

Expert Comment

by:Ray Paseur
Comment Utility

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:skykuhl
Comment Utility
0
 

Author Comment

by:skykuhl
Comment Utility
0
 
LVL 108

Expert Comment

by:Ray Paseur
Comment Utility
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
Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

 
LVL 108

Expert Comment

by:Ray Paseur
Comment Utility
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 108

Accepted Solution

by:
Ray Paseur earned 500 total points
Comment Utility
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:skykuhl
Comment Utility
Thank you very much.  I am trying these suggestions now.

Best regards,

Sky
0
 

Author Comment

by:skykuhl
Comment Utility
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 108

Expert Comment

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

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Author Note: Since this E-E article was originally written, years ago, formal testing has come into common use in the world of PHP.  PHPUnit (http://en.wikipedia.org/wiki/PHPUnit) and similar technologies have enjoyed wide adoption, making it possib…
Developers of all skill levels should learn to use current best practices when developing websites. However many developers, new and old, fall into the trap of using deprecated features because this is what so many tutorials and books tell them to u…
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
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 …

744 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

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now