Solved

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

Posted on 2014-11-04
10
180 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
  • 5
  • 4
10 Comments
 
LVL 54

Expert Comment

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

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
Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

 

Author Comment

by:Schuyler Kuhl
ID: 40422069
0
 
LVL 109

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 109

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 109

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 109

Expert Comment

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

Featured Post

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
How to stop user from going back to a previous page in PHP 3 35
SQL Result Set to XML 4 40
What does != "" mean in programming 8 42
How is this connection happening? 3 16
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…
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.
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

825 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