PHP SOAP call from CMD
Script is sending some data by PHP SOAP client, when I execute it from browser, everything is going fine. But when i try to execute it from CMD I'm getting error:
SOAP-ERROR: Encoding: string 'CBP\xe0...' is not a valid utf-8 string
My bat file looks like this:
@echo OFF
(
chcp 65001
"E:\xamp\xampp\php\php.exe" E:\xamp\xampp\htdocs\webapi开发者_StackOverflow中文版\index.php
)
With or without chcp I'm still getting error.
I've made a test charset check and all the time output is ASCII, even in browser.. PHP file is utf-8 encoded, and the bat file is in ANSI.
$a = 'test text';
echo mb_detect_encoding($a);
$b = mb_convert_encoding($a, "UTF-8", "auto");
echo mb_detect_encoding($b);
$c = iconv("ASCII", "UTF-8", $a);
echo mb_detect_encoding($c);
$d = utf8_encode($a);
echo mb_detect_encoding($d);
Any help would be appreciated.
This could seriously be a Windows related issue. Try it at the Linux command-line.
You also might try to run it through PHP-CGI rather than just the CLI. Personally, I have used PHP in some exotic situations when I was piping data, and even though the data seemed identical, it wasn't until I used the CGI version that it worked (you can still call it from the commandline).
It also might be the case that there's something significantly different about the environment while you're running in the webpage and the environment while you're running from the CLI, as far as your needs go. For example, when PHP runs from the CLI, you have access to the system's environment variables (in $_SERVER). However, these are not there when inside the webpage. You can see if there's a difference in what cURL's sending by getting a final copy of the request (and/or headers) while in both environments, and comparing them at the byte level. This is probably your best bet.
You also might try to include the actual (or similar) SOAP code so we'd know what the crap you were talking about, firsthand, rather than blindly throwing darts at possible answers.
(If you liked this answer, accept it and vote me up.)
Dustin
精彩评论