简体   繁体   English

PHP SOAP 来自 CMD 的调用

[英]PHP SOAP call from CMD

Script is sending some data by PHP SOAP client, when I execute it from browser, everything is going fine.脚本正在通过 PHP SOAP 客户端发送一些数据,当我从浏览器执行它时,一切正常。 But when i try to execute it from CMD I'm getting error:但是当我尝试从 CMD 执行它时,我遇到了错误:

SOAP-ERROR: Encoding: string 'CBP\xe0...' is not a valid utf-8 string SOAP-ERROR: Encoding: string 'CBP\xe0...' is not a valid utf-8 string

My bat file looks like this:我的 bat 文件如下所示:

@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.无论有没有 chcp,我仍然会出错。

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.我已经进行了测试字符集检查,output 一直是 ASCII,即使在浏览器中也是如此。

$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.这可能是与 Windows 相关的问题。 Try it at the Linux command-line.在 Linux 命令行中尝试一下。

You also might try to run it through PHP-CGI rather than just the CLI.您也可以尝试通过 PHP-CGI 而不仅仅是 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).就个人而言,当我在管道数据时,我曾在一些特殊情况下使用过 PHP,即使数据看起来相同,但直到我使用 CGI 版本才有效(您仍然可以从命令行调用它)。

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.就您的需要 go 而言,您在网页中运行时的环境和从 CLI 运行时的环境也可能存在显着不同的情况。 For example, when PHP runs from the CLI, you have access to the system's environment variables (in $_SERVER).例如,当 PHP 从 CLI 运行时,您可以访问系统的环境变量(在 $_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.您可以通过在两种环境中获取请求(和/或标头)的最终副本并在字节级别比较它们来查看 cURL 发送的内容是否存在差异。 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.您也可以尝试包含实际的(或类似的)SOAP 代码,以便我们直接知道您在说什么废话,而不是盲目地向可能的答案投掷飞镖。

(If you liked this answer, accept it and vote me up.) (如果您喜欢这个答案,请接受并投票给我。)

Dustin达斯汀

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM