views:

1662

answers:

5

if I use Firefox and access http://svcs.ebay.com/services/search/FindingService/v1 I get some sort of XML in respose, when I do that through PHP I get Internal Server Error 500

$ php -r 'print_r(simplexml_load_file("http://svcs.ebay.com/services/search/FindingService/v1"));'
PHP Warning:  simplexml_load_file(http://svcs.ebay.com/services/search/FindingService/v1): failed to open stream: HTTP request failed! HTTP/1.1 500 Internal Server Error
 in Command line code on line 1
PHP Stack trace:
PHP   1. {main}() Command line code:0
PHP   2. simplexml_load_file() Command line code:1
PHP Warning:  simplexml_load_file(): I/O warning : failed to load external entity "http://svcs.ebay.com/services/search/FindingService/v1" in Command line code on line 1
PHP Stack trace:
PHP   1. {main}() Command line code:0
PHP   2. simplexml_load_file() Command line code:1
$ 
+1  A: 

When I visit http://svcs.ebay.com/services/search/FindingService/v1 in firefox, firebug reports that the HTTP reponse code is indeed 500. (even though it sends some XML in the request body)

You're calling the web service in the wrong way.

Yes, you got XML back, but the response code is 500, meaning your URL is wrong.

Calling ximlexml_load_file via url wrappers expects a success code.

That said, you could probably get at the data anyway. Maybe.

But you should figure out how the service wants you to to query.

timdev
you saying simplexml_load_file prevents me to see data content because it received 500? do you know if I can somehow bypass it, or put it in some sort of debug mode where I can see everything that was passed and came back?
alexus
You should use curl to get the content and import it in simple_xml
RageZ
Yes, if the fopen wrappers that simplexml_load relies on won't give you access to the content of the 500-status reply, then either use curl, or possibly, you can use @ to ignore the warning. You're getting warnings -- you should be able to ignore them.
timdev
500 is an error, so it makes sense for something like file_get_contents which relies on url wrappers to report it as such. Curl is more general purpose, and leaves it to you to deal with the details of what comes back.Cleanest thing to do is just use curl libraries, and handle the responses however you want. @ing stuff to suppress warnings is ... dirty.
timdev
+1  A: 

If you want to be able to read 500 request data use curl

<?php
// create a new cURL resource
$ch = curl_init();

// set URL and other appropriate options
curl_setopt($ch, CURLOPT_URL, "http://svcs.ebay.com/services/search/FindingService/v1");
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);

// grab URL and pass it to the browser
$xml = curl_exec($ch);
$simpleXml = simplexml_load_string($xml);
// close cURL resource, and free up system resources
curl_close($ch);
?>
RageZ
is there a way to use simplexml_load_file() even though I get 500?
alexus
not with file_get_content, file_get_content expect an not error HTTP status or it will throw an error
RageZ
i dont see file_get_content in your example...
alexus
that's why I use curl.
RageZ
+1  A: 

When I go to that site, I get:

<ms:errorMessage>
−
<error>
<errorId>2038</errorId>
<domain>SOA</domain>
<severity>Error</severity>
<category>System</category>
<message>Missing SOA operation name header</message>
</error>
</ms:errorMessage>

So it would seem that the URL is to a web service and probably requires some kind of authentication or at least input data in the request header. The HTTP response 500, according to Wikipedia, is a generic error meaning that the server can't specify the problem but knows there was one. Here's the best part of that article:

Response status codes beginning with the digit "5" indicate cases in which the server is aware that it has encountered an error or is otherwise incapable of performing the request. Except when responding to a HEAD request, the server should include an entity containing an explanation of the error situation, and indicate whether it is a temporary or permanent condition.

All that combined, I'd have to say your issue is that your are trying to grab a file from a remote server using a method that assumes you have some directory-level access to that file, and the server is responding with "Um, what?"

If you want to get the actual XML error as though you were in Firefox, use cURL:

$ebay_url = "http://svcs.ebay.com/services/search/FindingService/v1";
$ebay_page = curl_init();

curl_setopt($ebay_page, CURLOPT_RETURNTRANSFER, true); //output to string.
curl_setopt($ebay_page, CURLOPT_URL, $ebay_url); //set the url for the request.

$ebay_response = curl_exec($ebay_page);

print_r(simplexml_load_string($ebay_response));

If you want to actually get something back more meaningful, I would look at PHP's SoapClient methods and the actual ebay web service documentation.

Anthony
A: 

The http headers need to be set specifying the operation to be executed. If you read how to make a call using the finding API, the article mentions the following http headers that need to be set:

X-EBAY-SOA-SERVICE-NAME: FindingService
X-EBAY-SOA-OPERATION-NAME: findItemsAdvanced <-- whatever call you are making
X-EBAY-SOA-SERVICE-VERSION: 1.0.0
X-EBAY-SOA-GLOBAL-ID: EBAY-US
X-EBAY-SOA-SECURITY-APPNAME: MyAppID
X-EBAY-SOA-REQUEST-DATA-FORMAT: XML
X-EBAY-SOA-MESSAGE-PROTOCOL: XML

Once those are set your call shoud work fine.

A: 

Maybe you want to try the following URL. When I do, I get back the XML and a 200 response.

http://svcs.ebay.com/services/search/FindingService/v1?wsdl

grantwparks
The fact that using ?wsdl gets me WSDL says this is a SOAP server you're calling. In which case you're probably going to have to POST a proper SOAP request to actually do something.
grantwparks