来自 CMD 的 PHP SOAP 调用
脚本正在通过 PHP SOAP 客户端发送一些数据,当我从浏览器执行它时,一切正常。但是当我尝试从 CMD 执行它时,我收到错误:
SOAP 错误:编码:字符串“CBP\xe0...”不是有效的 utf-8 字符串
我的 bat 文件如下所示:
@echo OFF
(
chcp 65001
"E:\xamp\xampp\php\php.exe" E:\xamp\xampp\htdocs\webapi\index.php
)
无论有或没有 chcp,我仍然收到错误。
我已经进行了测试字符集检查,并且所有时间输出都是 ASCII,即使在浏览器中也是如此。 PHP文件是utf-8编码的,bat文件是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);
任何帮助将不胜感激。
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\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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这可能是一个严重的 Windows 相关问题。在 Linux 命令行中尝试一下。
您还可以尝试通过 PHP-CGI 而不仅仅是 CLI 来运行它。就我个人而言,当我传输数据时,我在一些特殊情况下使用了 PHP,尽管数据看起来相同,但直到我使用 CGI 版本时它才起作用(您仍然可以从命令行调用它)。
根据您的需要,您在网页中运行时的环境和从 CLI 运行时的环境也可能存在显着不同。例如,当 PHP 从 CLI 运行时,您可以访问系统的环境变量(在 $_SERVER 中)。然而,这些在网页内不存在。您可以通过在两种环境中获取请求(和/或标头)的最终副本并在字节级别进行比较来查看 cURL 发送的内容是否存在差异。这可能是您最好的选择。
您还可以尝试包含实际的(或类似的)SOAP 代码,这样我们就能第一手知道您在说什么,而不是盲目地向可能的答案扔飞镖。
(如果您喜欢这个答案,请接受并投票给我。)
达斯汀
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