0

I want to read XML data from a URL in Magento.

I have three textboxes. One is for baseurl and others are for username and password respectively. when i enter these values i get url like "http://xyz.com/somefile.html?username=username&password=password"

I am using the curl method to get content of the url but nothing happens. Here is my code

$url='myurl'; 

$ch = curl_init();
$timeout = 5;
curl_setopt($ch,CURLOPT_URL,$url);
curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch,CURLOPT_CONNECTTIMEOUT,$timeout);
$data = curl_exec($ch);
curl_close($ch);

I think there may be some problem with url because when i run this url on browser instead of showing xml contents it asks me to open or save the xml file.

Can anyone help me with this? I can not change the url so please suggest me some code that works with this type of url.

5
  • It may be a problem with the URL, but just showing that popup box to download is not an indication of this. It's an indication that the web server has provided a content type that your browser doesn't know how to display, so is suggesting that you download it first, then try and view it. If you change the content type returned at the URL to something like text/plain, the the browser will display it just fine. Commented Mar 23, 2011 at 13:40
  • For security reasons, you should never pass password over a GET request, if its a real request. Commented Mar 23, 2011 at 13:51
  • 1
    @Frank Explain? GET is no more insecure than POST. If you catch the HTTP request you'll be able to see both GET and POST variables. Apart from appearing in the URL bar of the web browser (which wouldn't be the case here anyway) there is no difference. Commented Mar 24, 2011 at 14:03
  • @nick- I thought that url is working like a download link so i said that.. Commented Mar 25, 2011 at 8:49
  • thnk you friends for answers. i ran it on server.... it's working.. Commented Apr 2, 2011 at 6:43

1 Answer 1

0

Get the cURL command line tool from its website and then run it like this:

curl -i "http://xyz.com/somefile.html?username=username&password=password"

That's an easy and reliable way to see what's going on at the HTTP level.

Alternatively, use Firefox with Firebug to find out what's going on.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.