search
HomeBackend DevelopmentPHP TutorialXML 解析错误:格式不佳?求解

XML 解析错误:格式不佳位置:http://www.xxx.com/admin/order.php?act=operate行 1,列 6:http://xxx.com/wuliu.php?Request=<?xml version='1.0' encoding='UTF-8'?>-----^

提示这个错误
        $wj_curl = new wj_curl();        //var_dump($wj_curl :: ss());        $resR = $wj_curl -> xmlEncode($RequestOrderviews);        //print_r($resR);        $url = 'http://xxxx.com/wuliu.php?Request='.$resR.'&MD5='.$md5.'&Action=RequestOrder';        print_r($url);

我是这样打印的,$resR是一个xml数据。格式是正确的如下
RequestOrder><WaybillNo>wjys2016050564377</WaybillNo><ClientCode>2016050564377</ClientCode><Holiday>1</Holiday><ReplCost>0</ReplCost><StmtForm>1</StmtForm><TrustClientCode>421</TrustClientCode><TrustPerson>仓库</TrustPerson><TrustUnit>迁安市电子商务服务中心</TrustUnit><TrustZipCode>064400</TrustZipCode><TrustProvince>河北省</TrustProvince><TrustCity>唐山市</TrustCity><TrustArea>迁安市</TrustArea><TrustAddress>迁安电商谷</TrustAddress><TrustMobile>0315-7572555</TrustMobile><TrustTel>0315-7572555</TrustTel><GetPerson>乔鹤</GetPerson><GetUnit>25号楼四单元301</GetUnit><GetZipCode>064400</GetZipCode><GetProvince>河北省</GetProvince><GetCity>迁安市</GetCity><GetArea>5 大王庄平改楼</GetArea><GetAddress>25号楼四单元301</GetAddress><GetTel>15232682888</GetTel><GetMobile>15232682888</GetMobile><InsForm>0</InsForm><InsureValue>0</InsureValue><WorkType>0</WorkType><OrderType>普通订单</OrderType><GoodsInfo><Good><GoodsName>乡伊香核桃油  1000ml</GoodsName><GoodsValue>168.00</GoodsValue><GoodsBarCode>6944219400234</GoodsBarCode><ListType>0</ListType><ISInvoice>0</ISInvoice></Good></GoodsInfo><GoodsNum>1</GoodsNum><GoodsHav>0</GoodsHav></RequestOrder>

我不明白的是 这里的$url我只是给xml拼接进去了就给报错?这是为什么?我的目的向一个借口发送xml数据,我打算通过curl post方式 发送。
下面是我的curl
public static function my_curl($uri,$xmlData=array()){        $url = $uri;  //接收xml数据的文件        $header = array("content-type: application/x-www-form-urlencoded;");        //定义content-type为xml,注意是数组        $ch = curl_init ($url);        curl_setopt($ch, CURLOPT_URL, $url);        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);        curl_setopt($ch, CURLOPT_HTTPHEADER, $header);        curl_setopt($ch, CURLOPT_POST, 1);        curl_setopt($ch, CURLOPT_POSTFIELDS, $xmlData);        $response = curl_exec($ch);        if(curl_errno($ch)){            print curl_error($ch);        }        curl_close($ch);    }

完全不知道怎么做求大神们帮助下。


回复讨论(解决方案)

你都用post了 为什么要把xml文档放在url上面呢, 然后你模拟的post提交 里面提交的数据还是数组。。。。有点矛盾。。

不知道你要干什么
也不知道对方能接收什么

我发现 只要是在xml数据前面加上任何字符。都会提示格式不加。  那他的接口要求的数据格式

请求采用HTTP标准的POST协议采用,请求参数通过xml格式,验证的模式定为MD5验证。抛送格式为:http://*****.php?Request=Xml&MD5=XXX&Action=请求指令。编码格式为:UTF-8 
我怎么给他发过去啊???

这是他的整个数据请求

http://xxx.xx.xx.xxx:850/order.php?Request=<RequestOrder>	< WaybillNo>1111102354</ WaybillNo>< ClientCode>Sp001</ ClientCode>< Holiday>1</ Holiday>< ReplCost>20.2</ ReplCost>< StmtForm>0</ StmtForm>< TrustClientCode>111234</ TrustClientCode><TrustPerson>王三</ TrustPerson>< TrustUnit>好乐买</ TrustUnit>< TrustZipCode>001</ TrustZipCode><TrustProvince>北京</ TrustProvince>< TrustCity>北京市</ TrustCity><TrustArea>朝阳区</TrustArea>< TrustAddress>三里屯SOHO大厦3D15层</ TrustAddress>< TrustMobile>13436709024</ TrustMobile>< TrustTel>010-3650092</ TrustTel>< GetPerson>李三</ GetPerson>< GetUnit>XXX公司</ GetUnit>< GetZipCode>010</ GetZipCode>< GetProvince>广东省</ GetProvince><GetCity>深圳市</ GetCity><GetArea>罗湖区</ GetArea>< GetAddress>人民南路1号京广大厦A406室</ GetAddress>< GetTel>755-3456789</ GetTel>< GetMobile>13436700238</ GetMobile>< InsForm>0</ InsForm>< InsureValue></ InsureValue>< GoodsValue>30.45</ GoodsValue>< WorkType>0</ WorkType><OrderType>xxx< /OrderType><GoodsInfo><Good>< GoodsName>XXX商品</ GoodsName>< GoodsValue >20.34 </ GoodsValue ><GoodsBarCode>00987</ GoodsBarCode><ListType>0</ ListType>< ISInvoice>0< ISInvoice></Good><Good>< GoodsName>YYY商品</ GoodsName>< GoodsValue >20 </ GoodsValue ><GoodsBarCode>00987</ GoodsBarCode><ListType>0</ ListType>< ISInvoice>1< ISInvoice></Good></GoodsInfo><GoodsNum>2</GoodsNum>< GoodsHav>2</ GoodsHav></ RequestOrder>&MD5=SDJ21W3E1WRE1SDF2ER34D1RTRE113DF&Action=RequestOrder

个人拙见:他既然要用post请求, 那http://*****.php 这个就是 url
                    Request=Xml&MD5=XXX&Action=请求指令。
                    这些就是参数,是不是要把这个三个参数组成xml文档?

那你直接get过去就行了啊 

那你直接get过去就行了啊 


将xml数据转换为字符串。然后拼接url好像就行了

不知道你要干什么
也不知道对方能接收什么


我要向一个接口发送数据请求,格式如下
http://xxx.xx.xx.xxx:850/order.php?Request=<RequestOrder>	< WaybillNo>1111102354</ WaybillNo>< ClientCode>Sp001</ ClientCode>< Holiday>1</ Holiday>< ReplCost>20.2</ ReplCost>< StmtForm>0</ StmtForm>< TrustClientCode>111234</ TrustClientCode><TrustPerson>王三</ TrustPerson>< TrustUnit>好乐买</ TrustUnit>< TrustZipCode>001</ TrustZipCode><TrustProvince>北京</ TrustProvince>< TrustCity>北京市</ TrustCity><TrustArea>朝阳区</TrustArea>< TrustAddress>三里屯SOHO大厦3D15层</ TrustAddress>< TrustMobile>13436709024</ TrustMobile>< TrustTel>010-3650092</ TrustTel>< GetPerson>李三</ GetPerson>< GetUnit>XXX公司</ GetUnit>< GetZipCode>010</ GetZipCode>< GetProvince>广东省</ GetProvince><GetCity>深圳市</ GetCity><GetArea>罗湖区</ GetArea>< GetAddress>人民南路1号京广大厦A406室</ GetAddress>< GetTel>755-3456789</ GetTel>< GetMobile>13436700238</ GetMobile>< InsForm>0</ InsForm>< InsureValue></ InsureValue>< GoodsValue>30.45</ GoodsValue>< WorkType>0</ WorkType><OrderType>xxx< /OrderType><GoodsInfo><Good>< GoodsName>XXX商品</ GoodsName>< GoodsValue >20.34 </ GoodsValue ><GoodsBarCode>00987</ GoodsBarCode><ListType>0</ ListType>< ISInvoice>0< ISInvoice></Good><Good>< GoodsName>YYY商品</ GoodsName>< GoodsValue >20 </ GoodsValue ><GoodsBarCode>00987</ GoodsBarCode><ListType>0</ ListType>< ISInvoice>1< ISInvoice></Good></GoodsInfo><GoodsNum>2</GoodsNum>< GoodsHav>2</ GoodsHav></ RequestOrder>&MD5=SDJ21W3E1WRE1SDF2ER34D1RTRE113DF&Action=RequestOrder

格式要求为
请求采用HTTP标准的POST协议采用,请求参数通过xml格式,验证的模式定为MD5验证。抛送格式为:http://*****.php?Request=Xml&MD5=XXX&Action=请求指令。编码格式为:UTF-8 

不知道你要干什么
也不知道对方能接收什么


提供一组数组
Array(    'WaybillNo' => 'wjys2016050564377',    'ClientCode' => '2016050564377',    'Holiday' => '1',    'ReplCost' => '0',    'StmtForm' => '1',    'TrustClientCode' => '421',    'TrustPerson' =>'仓库',    'TrustUnit' => '商务服务中心',    'TrustZipCode' => '064400',    'TrustProvince' => '河北省',    'TrustCity' => '市',    'TrustArea' => '市',    'TrustAddress' => '谷',    'TrustMobile' => '0355',    'TrustTel' => '055',    'GetPerson' => '乔鹤',    'GetUnit' => '25号楼四单元301',    'GetZipCode' => '064400',    'GetProvince' => '河北省',    'GetCity' => '市',    'GetArea' => '平改楼',    'GetAddress' => '25号楼四单元301',    'GetTel' => '15232682888',    'GetMobile' => '15232682888',    'InsForm' => '0',    'InsureValue' => '0',    'WorkType' => '0',    'OrderType' => '普通订单',    'GoodsInfo' => Array        (            'Good' => Array                (                    'GoodsName' => '乡伊香核桃油',                    'GoodsValue' => '168',                    'GoodsBarCode' => '6944219400234',                    'ListType' => '0',                    'ISInvoice' => '0',                ),        ),    'GoodsNum' => 1,    'GoodsHav' => 0,)

既然是 请求采用HTTP标准的POST协议
那么你放在 url 里做什么?

既然是 请求采用HTTP标准的POST协议
那么你放在 url 里做什么?


他给我的例子不是http://xxx.xx.xx.xxx:850/order.php?Request=  xml信息  这样的吗?难道不是放在url中?

好像是的
但应理解为,虽然数据放在了 url 上,但访问方式还是 post 的
即:CURLOPT_POST 为真,CURLOPT_POSTFIELDS 为空(或没有)

用POST方式,需要把数据放在CURLOPT_POSTFIELDS,
而放在url的参数要用GET来获取

Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
The Continued Use of PHP: Reasons for Its EnduranceThe Continued Use of PHP: Reasons for Its EnduranceApr 19, 2025 am 12:23 AM

What’s still popular is the ease of use, flexibility and a strong ecosystem. 1) Ease of use and simple syntax make it the first choice for beginners. 2) Closely integrated with web development, excellent interaction with HTTP requests and database. 3) The huge ecosystem provides a wealth of tools and libraries. 4) Active community and open source nature adapts them to new needs and technology trends.

PHP and Python: Exploring Their Similarities and DifferencesPHP and Python: Exploring Their Similarities and DifferencesApr 19, 2025 am 12:21 AM

PHP and Python are both high-level programming languages ​​that are widely used in web development, data processing and automation tasks. 1.PHP is often used to build dynamic websites and content management systems, while Python is often used to build web frameworks and data science. 2.PHP uses echo to output content, Python uses print. 3. Both support object-oriented programming, but the syntax and keywords are different. 4. PHP supports weak type conversion, while Python is more stringent. 5. PHP performance optimization includes using OPcache and asynchronous programming, while Python uses cProfile and asynchronous programming.

PHP and Python: Different Paradigms ExplainedPHP and Python: Different Paradigms ExplainedApr 18, 2025 am 12:26 AM

PHP is mainly procedural programming, but also supports object-oriented programming (OOP); Python supports a variety of paradigms, including OOP, functional and procedural programming. PHP is suitable for web development, and Python is suitable for a variety of applications such as data analysis and machine learning.

PHP and Python: A Deep Dive into Their HistoryPHP and Python: A Deep Dive into Their HistoryApr 18, 2025 am 12:25 AM

PHP originated in 1994 and was developed by RasmusLerdorf. It was originally used to track website visitors and gradually evolved into a server-side scripting language and was widely used in web development. Python was developed by Guidovan Rossum in the late 1980s and was first released in 1991. It emphasizes code readability and simplicity, and is suitable for scientific computing, data analysis and other fields.

Choosing Between PHP and Python: A GuideChoosing Between PHP and Python: A GuideApr 18, 2025 am 12:24 AM

PHP is suitable for web development and rapid prototyping, and Python is suitable for data science and machine learning. 1.PHP is used for dynamic web development, with simple syntax and suitable for rapid development. 2. Python has concise syntax, is suitable for multiple fields, and has a strong library ecosystem.

PHP and Frameworks: Modernizing the LanguagePHP and Frameworks: Modernizing the LanguageApr 18, 2025 am 12:14 AM

PHP remains important in the modernization process because it supports a large number of websites and applications and adapts to development needs through frameworks. 1.PHP7 improves performance and introduces new features. 2. Modern frameworks such as Laravel, Symfony and CodeIgniter simplify development and improve code quality. 3. Performance optimization and best practices further improve application efficiency.

PHP's Impact: Web Development and BeyondPHP's Impact: Web Development and BeyondApr 18, 2025 am 12:10 AM

PHPhassignificantlyimpactedwebdevelopmentandextendsbeyondit.1)ItpowersmajorplatformslikeWordPressandexcelsindatabaseinteractions.2)PHP'sadaptabilityallowsittoscaleforlargeapplicationsusingframeworkslikeLaravel.3)Beyondweb,PHPisusedincommand-linescrip

How does PHP type hinting work, including scalar types, return types, union types, and nullable types?How does PHP type hinting work, including scalar types, return types, union types, and nullable types?Apr 17, 2025 am 12:25 AM

PHP type prompts to improve code quality and readability. 1) Scalar type tips: Since PHP7.0, basic data types are allowed to be specified in function parameters, such as int, float, etc. 2) Return type prompt: Ensure the consistency of the function return value type. 3) Union type prompt: Since PHP8.0, multiple types are allowed to be specified in function parameters or return values. 4) Nullable type prompt: Allows to include null values ​​and handle functions that may return null values.

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

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

Hot Tools

ZendStudio 13.5.1 Mac

ZendStudio 13.5.1 Mac

Powerful PHP integrated development environment

mPDF

mPDF

mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),

MinGW - Minimalist GNU for Windows

MinGW - Minimalist GNU for Windows

This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools