Solved

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

Posted on 2014-11-04
10
185 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 58

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
Stressed Out?

Watch some penguins on the livecam!

 
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

Secure Your WordPress Site: 5 Essential Approaches

WordPress is the web's most popular CMS, but its dominance also makes it a target for attackers. Our eBook will show you how to:

Prevent costly exploits of core and plugin vulnerabilities
Repel automated attacks
Lock down your dashboard, secure your code, and protect your users

Question has a verified solution.

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

Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo‚Ķ
3 proven steps to speed up Magento powered sites. The article focus is on optimizing time to first byte (TTFB), full page caching and configuring server for optimal performance.
The viewer will learn how to dynamically set the form action using jQuery.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

617 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