简体   繁体   English

如何通过php将XML发送到规范URL?

[英]how can I send a XML to spec URL though php?

How can I send a XML to spec URL? 如何将XML发送到规范URL?

Every time a form is sent I want to send a xml file to a url ... how do I do that? 每次发送表单时,我都想将xml文件发送到url ...我该怎么做?

NOTE: xml file to be sent is always the same so I do not need to create new xml file each time .. 注意:要发送的xml文件始终相同,因此我不需要每次都创建新的xml文件。

Something along the lines of: 类似于以下内容:

  1. Load XML into $xmldata. 将XML加载到$ xmldata中。
  2. Create headers: 创建标题:

     $header[] = "Host: www.site.com"; $header[] = "Content-type: text/xml"; $header[] = "Content-length: ".strlen($xmldata) . "\\r\\n"; $header[] = $xmldata; 
  3. Run CURL: 运行CURL:

     $ch = curl_init(); curl_setopt($ch, CurlOPT_url, "http://www.site.com/receiving_script.php"); curl_setopt($ch, CurlOPT_RETURNTRANSFER, 1); curl_setopt($ch, CurlOPT_HTTPHEADER, $header); curl_setopt($ch, CurlOPT_CUStoMREQUEST, 'POST'); curl_exec($ch); curl_close($ch); 

This is just a sample code, but you get the idea. 这只是一个示例代码,但是您明白了。

<input type="hidden" name="xmlfile" value="<?php echo htmlspecialchars($xml)" />

would do the trick. 会成功的 But if the XML is always the same, why not just put the file onto the server and read it there, rather than wasting bandwidth sending it each time? 但是,如果XML始终相同,为什么不将文件放到服务器上并在服务器上读取文件,而不是浪费每次发送文件的带宽呢?

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

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