Solved

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

Posted on 2014-11-04
10
175 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 52

Expert Comment

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

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:skykuhl
ID: 40422060
0
 

Author Comment

by:skykuhl
ID: 40422069
0
 
LVL 108

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
DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

 
LVL 108

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 108

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:skykuhl
ID: 40423852
Thank you very much.  I am trying these suggestions now.

Best regards,

Sky
0
 

Author Comment

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

Expert Comment

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

Featured Post

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Keep getting 503 on Curl request 6 30
php string masking 4 28
phpmailer in WHILE loop - weird results 10 27
Move wordpress site 3 18
The Confluence of Individual Knowledge and the Collective Intelligence At this writing (summer 2013) the term API (http://dictionary.reference.com/browse/API?s=t) has made its way into the popular lexicon of the English language.  A few years ago, …
This article discusses how to create an extensible mechanism for linked drop downs.
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 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 …

910 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

24 Experts available now in Live!

Get 1:1 Help Now