如何在没有cURL的情况下使用PHP HTTP发布XML文件?
发布时间:2020-12-14 01:18:44 所属栏目:Linux 来源:网络整理
导读:参见英文答案 How to post data in PHP using file_get_contents?????????????????????????????????????3个 我有一个从Table In MySql创建的XML,我需要创建一个HTTP Post来将XML插入到Web服务中. Web Service只接受SOAP,HTTP POST和HTTP GET方法.我尝试以不
参见英文答案 >
How to post data in PHP using file_get_contents?????????????????????????????????????3个
我有一个从Table In MySql创建的XML,我需要创建一个HTTP Post来将XML插入到Web服务中. Web Service只接受SOAP,HTTP POST和HTTP GET方法.我尝试以不同的方式发出HTTP POST请求而根本没有运气.我之前从未使用过SOAP.如何进行HTTP POST或SOAP请求? post_xml.xml: <?xml version="1.0" encoding="utf-8"?> <?ADF version="1.0"?> <adf> <prospect><id sequence="1" source="xxxs">37</id> <requestdate>2013-07-10 06:10:42</requestdate> <vehicle interest="buy" status="new"> <year>2013</year> <make>12</make> <model>21</model> <trim>Sport</trim> </vehicle> <customer> <contact> <name part="first">Jay</name> <name part="last">11z</name> <email>test@gmail.com</email> <phone time="morning" type="voice" preferredcontact="1">99999999</phone> <address> <street line="1">1130 E Test</street> <city>sa</city> <regioncode>Z</regioncode> <postalcode>79924</postalcode> <country>USA</country> </address> </contact> </prospect> </adf> client1.php(HTTP POST代码) $xml = file_get_contents('post_xml.xml'); $url = 'http://stg.sa.com/post.asmx/'; $post_data = array ("XML" => $xml); $stream_options = array( $url => array( 'method' => 'POST','header' => 'Content-type: application/x-www-form-urlencoded' . "rn",'content' => http_build_query($post_data) ) ); $context = stream_context_create($stream_options); $response = file_get_contents($url,null,$context); Web Service的HTTP POST规范: 以下是HTTP POST请求和响应示例. POST /st.asmx/Post HTTP/1.1 Host: stg.sa.com Content-Type: application/x-www-form-urlencoded Content-Length: length XML= string HTTP/1.1 200 OK Content-Type: text/xml; charset=utf-8 Content-Length: length <?xml version="1.0"?> xml 解决方法
我认为你的POST阵列是错误的
尝试: $xml = file_get_contents('post_xml.xml'); $url = 'http://stg.sa.com/post.asmx/'; $post_data = array( "xml" => $xml,); $stream_options = array( 'http' => array( 'method' => 'POST','header' => "Content-type: application/x-www-form-urlencodedrn",'content' => http_build_query($post_data),),); $context = stream_context_create($stream_options); $response = file_get_contents($url,$context); (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
相关内容
- linux – CentOS 6.5 mdadm Raid 1 – raid数据检查期间的内
- 使用supervisord运行django自定义管理命令
- SELinux与AppArmor对阵grsecurity
- linux之时间日期类相关的指令
- linux – 我的CentOS服务器上是否已经有一个硬件监视器?
- linux – 检测stdout是否被重定向到管道(而不是文件,字符设
- linux – 如何在PuTTY控制台窗口中搜索文本
- linux – 用于低延迟10GbE – > 1GbE网络的TCP拥塞控制?
- java – 在linux上执行jdb传输错误202:绑定失败
- Active Directory的Linux身份验证,无需加入域