PHP XML error parsing SOAP payload on line 1_PHP
Jun 01, 2016 pm 12:18 PM
WebService,想必大家都比較熟悉,是由“服務(wù)提供方”向“服務(wù)調(diào)用方”提供服務(wù)的一種方式。里面有幾項(xiàng)關(guān)鍵的技術(shù):
XML:描述數(shù)據(jù)的標(biāo)準(zhǔn)方法
SOAP:簡(jiǎn)單對(duì)象訪問(wèn)協(xié)議,用于信息交換
WSDL:Web服務(wù)描述語(yǔ)言
UDDI:通用描述、發(fā)現(xiàn)與集成,它是一種獨(dú)立于平臺(tái)的,基于XML語(yǔ)言的用于在互聯(lián)網(wǎng)上描述商務(wù)的協(xié)議。
SOAP默認(rèn)傳輸?shù)亩际荱TF-8的編碼,這也決定了默認(rèn)情況下WebService用的也是UTF-8編碼。
現(xiàn)在維護(hù)的那個(gè)項(xiàng)目是一個(gè)PHP項(xiàng)目,編碼用的全是GBK,在調(diào)用自身提供的WebService方法時(shí),就會(huì)遇到編碼問(wèn)題了。PHP頁(yè)面調(diào)用WebService,而這個(gè)WebService又調(diào)用的是另一個(gè)調(diào)用COM組件的PHP類。大概場(chǎng)景就是這樣。
復(fù)制代碼 代碼如下:
PHP頁(yè)面(GBK) -> WebService(UTF-8) -> PHP類(GBK)
在未遇到問(wèn)題之前,一切都是風(fēng)平浪靜的,就這樣過(guò)了很多年。有一天,公司收購(gòu)了其它公司,為了整合服務(wù),用戶信息也整合到一起了,原公司所有用戶的帳戶都是由英文字符加數(shù)字組成的,而收購(gòu)的這個(gè)公司沒(méi)有做這樣的限定,帳戶有漢字的情況。整合之后,問(wèn)題出現(xiàn)了,“error in msg parsing: XML error parsing SOAP payload on line 1: Invalid character [detail]”!
PHP剛接觸不久,不是甚熟,而且NetBeans的調(diào)試灰常不好整。所以就打開(kāi)VS,引用WebService,開(kāi)始測(cè)試。返回的結(jié)果,找不到用戶,而且是亂碼,OK,看了一下之后,由于WebService的UTF-8編碼傳給PHP類時(shí),編碼不一致所導(dǎo)致!轉(zhuǎn)換為GBK再傳過(guò)去,收到數(shù)據(jù)后,找到用戶,但還是亂碼。將返回過(guò)來(lái)的數(shù)據(jù)再次轉(zhuǎn)換為UTF-8之后,一切OK!VS下測(cè)試一切正常!上測(cè)試機(jī)!開(kāi)始測(cè)試!打開(kāi)之后,亂碼!仍然是“error in msg parsing: XML error parsing SOAP payload on line 1: Invalid character [detail]”囧!
靜下心來(lái),繼續(xù)分析!應(yīng)該是PHP頁(yè)面調(diào)用WebService時(shí)所導(dǎo)致!VS下面的那個(gè)測(cè)試頁(yè)面是UTF-8的,他們之間沒(méi)有問(wèn)題,但PHP的這個(gè)頁(yè)面是GBK的。再次修改后,一切又恢復(fù)平靜了。
復(fù)制代碼 代碼如下:
調(diào)用:PHP頁(yè)面,參數(shù)轉(zhuǎn)換為UTF-8 -> WebService,轉(zhuǎn)換為GBK后 -> PHP類
返回:PHP類 -> WebService,收到后轉(zhuǎn)化為UTF-8 -> PHP頁(yè)面,轉(zhuǎn)換為GBK

Hot AI Tools

Undress AI Tool
Undress images for free

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

PHPhasthreecommentstyles://,#forsingle-lineand/.../formulti-line.Usecommentstoexplainwhycodeexists,notwhatitdoes.MarkTODO/FIXMEitemsanddisablecodetemporarilyduringdebugging.Avoidover-commentingsimplelogic.Writeconcise,grammaticallycorrectcommentsandu

The key steps to install PHP on Windows include: 1. Download the appropriate PHP version and decompress it. It is recommended to use ThreadSafe version with Apache or NonThreadSafe version with Nginx; 2. Configure the php.ini file and rename php.ini-development or php.ini-production to php.ini; 3. Add the PHP path to the system environment variable Path for command line use; 4. Test whether PHP is installed successfully, execute php-v through the command line and run the built-in server to test the parsing capabilities; 5. If you use Apache, you need to configure P in httpd.conf

PHPisaserver-sidescriptinglanguageusedforwebdevelopment,especiallyfordynamicwebsitesandCMSplatformslikeWordPress.Itrunsontheserver,processesdata,interactswithdatabases,andsendsHTMLtobrowsers.Commonusesincludeuserauthentication,e-commerceplatforms,for

TohandlefileoperationsinPHP,useappropriatefunctionsandmodes.1.Toreadafile,usefile_get_contents()forsmallfilesorfgets()inaloopforline-by-lineprocessing.2.Towritetoafile,usefile_put_contents()forsimplewritesorappendingwiththeFILE_APPENDflag,orfwrite()w

The basic syntax of PHP includes four key points: 1. The PHP tag must be ended, and the use of complete tags is recommended; 2. Echo and print are commonly used for output content, among which echo supports multiple parameters and is more efficient; 3. The annotation methods include //, # and //, to improve code readability; 4. Each statement must end with a semicolon, and spaces and line breaks do not affect execution but affect readability. Mastering these basic rules can help write clear and stable PHP code.

How to start writing your first PHP script? First, set up the local development environment, install XAMPP/MAMP/LAMP, and use a text editor to understand the server's running principle. Secondly, create a file called hello.php, enter the basic code and run the test. Third, learn to use PHP and HTML to achieve dynamic content output. Finally, pay attention to common errors such as missing semicolons, citation issues, and file extension errors, and enable error reports for debugging.

The steps to install PHP8 on Ubuntu are: 1. Update the software package list; 2. Install PHP8 and basic components; 3. Check the version to confirm that the installation is successful; 4. Install additional modules as needed. Windows users can download and decompress the ZIP package, then modify the configuration file, enable extensions, and add the path to environment variables. macOS users recommend using Homebrew to install, and perform steps such as adding tap, installing PHP8, setting the default version and verifying the version. Although the installation methods are different under different systems, the process is clear, so you can choose the right method according to the purpose.

The key to writing Python's ifelse statements is to understand the logical structure and details. 1. The infrastructure is to execute a piece of code if conditions are established, otherwise the else part is executed, else is optional; 2. Multi-condition judgment is implemented with elif, and it is executed sequentially and stopped once it is met; 3. Nested if is used for further subdivision judgment, it is recommended not to exceed two layers; 4. A ternary expression can be used to replace simple ifelse in a simple scenario. Only by paying attention to indentation, conditional order and logical integrity can we write clear and stable judgment codes.
