note 107433 added to soapserver.handle
| From: | dub357 at gmail dot com | Date: | Wed, 08 Feb 2012 22:54:56 +0000 |
| Subject: | note 107433 added to soapserver.handle | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-185928@lists.php.net to get a copy of this message | ||
After much headache and looking through PHP source code, I finally found out why the handle()
function would immediately send back a fault with the string "Bad Request".
Turns out that my client was sending valid XML, but the first line of the XML was the actual XML
declaration:
<?xml version="1.0" encoding="UTF-8"?>
When the "handle" function in the SoapServer class is called, it first tries to parse the
XML. When the XML document can't be parsed, a "Bad Request" fault is returned and
execution of the script immediately stops. I assume that the XML parser built into PHP (libxml2)
already assumes the document to be XML and when it finds the declaration, it thinks it isn't
valid.
I added some XML parsing calls to my service before the handle() function is called to check for
valid XML and avoid the "Bad Request" fault. This also allows me to send back a more
suitable error message:
$parser = xml_parser_create("UTF-8");
if (!xml_parse($parser,$HTTP_RAW_POST_DATA,true)){
$webService->fault("500", "Cannot parse XML: ".
xml_error_string(xml_get_error_code($parser)).
" at line: ".xml_get_current_line_number($parser).
", column: ".xml_get_current_column_number($parser));
}
----
Server IP: 64.71.164.2
Probable Submitter: 129.57.8.35
----
Manual Page -- http://www.php.net/manual/en/soapserver.handle.php
Edit -- https://master.php.net/note/edit/107433
Del: integrated -- https://master.php.net/note/delete/107433/integrated
Del: useless -- https://master.php.net/note/delete/107433/useless
Del: bad code -- https://master.php.net/note/delete/107433/bad+code
Del: spam -- https://master.php.net/note/delete/107433/spam
Del: non-english -- https://master.php.net/note/delete/107433/non-english
Del: in docs -- https://master.php.net/note/delete/107433/in+docs
Del: other reasons-- https://master.php.net/note/delete/107433
Reject -- https://master.php.net/note/reject/107433
Search -- https://master.php.net/manage/user-notes.php