首页 > 开发 > PHP > 正文

php 接收与发送xml文件

2024-05-04 21:58:40
字体:
来源:转载
供稿:网友
  1. //接收xml: 
  2. $xml = file_get_contents('php://input'); 
  3.   
  4. //发送(post): 
  5. $xml_data = <xml>...</xml>"; 
  6. $url = http://dest_url; 
  7. $header[] = "Content-type: text/xml";//定义content-type为xml 
  8. curl_setopt($ch, CURLOPT_URL, $url); 
  9. curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); 
  10. curl_setopt($ch, CURLOPT_HTTPHEADER, $header); 
  11. curl_setopt($ch, CURLOPT_POST, 1); 
  12. curl_setopt($ch, CURLOPT_POSTFIELDS, $xml_data); 
  13. $response = curl_exec($ch); 
  14. if(curl_errno($ch)) 
  15.     print curl_error($ch); 
  16. curl_close($ch);  
  17.  //开源代码Vevb.com 
  18. //或者: 
  19. $fp = fsockopen($server, 80); 
  20. fputs($fp"POST $path HTTP/1.0rn"); 
  21. fputs($fp"Host: $serverrn"); 
  22. fputs($fp"Content-Type: text/xmlrn"); 
  23. fputs($fp"Content-Length: $contentLengthrn"); 
  24. fputs($fp"Connection: closern"); 
  25. fputs($fp"rn"); // all headers sent 
  26. fputs($fp$xml_data); 
  27. $result = ''
  28. while (!feof($fp)) { 
  29. $result .= fgets($fp, 128); 
  30. return $result

发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表