【问题标题】:hudson: how to POST this xml following a successful post?哈德森:如何在成功发布后发布此 xml?
【发布时间】:2011-05-04 18:28:30
【问题描述】:

我使用了 Firefox 的海报插件来发送一个 xml POST。这是从成功的 POST 到 hudson 服务器捕获的 HTTP 标头。我正在尝试使用 header() 函数在 php 中复制它。

POST /createItem?name=tellme HTTP/1.1
Host: somewhere.com
User-Agent: Mozilla/5.0 (Windows; U; Windows NT 6.0; en-US; rv:1.9.2.12) Gecko/20101026 Firefox/3.6.12 (.NET CLR 3.5.30729)
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Language: en-us,en;q=0.5
Accept-Encoding: gzip,deflate
Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7
Keep-Alive: 115
Connection: keep-alive
Content-Type: text/xml
Content-Length: 715
Cookie: JSESSIONID=69b4cb38635ae490d357bb6b21372507
Pragma: no-cache
Cache-Control: no-cache
<?xml version='1.0' encoding='UTF-8'?>
<project>
  <actions/>
  <description></description>
  <keepDependencies>false</keepDependencies>
  <properties/>
  <scm class="hudson.scm.NullSCM"/>
  <canRoam>true</canRoam>
  <disabled>false</disabled>
  <blockBuildWhenUpstreamBuilding>false</blockBuildWhenUpstreamBuilding>
  <triggers class="vector"/>
  <concurrentBuild>false</concurrentBuild>
  <builders>
    <hudson.tasks.Shell>
      <command></command>
    </hudson.tasks.Shell>
  </builders>
  <publishers/>
  <buildWrappers>
    <hudson.plugins.xvnc.Xvnc>
      <takeScreenshot>false</takeScreenshot>
    </hudson.plugins.xvnc.Xvnc>
  </buildWrappers>
</project>

这是我的 php 代码:

<?php


$data = file_get_contents("config.xml");

$post_data = $data;
$content_length = strlen($post_data);

header('POST /createItem?name=friends HTTP/1.1');
header('Host: somewhere.com');
header('Keep-Alive: 115');
header('Connection: keep-alive');
header('Content-type: text/xml');
header('Content-length: ' . trim($content_length));
header($post_data);

exit();

php代码失败并抛出:Warning: Header may not contain more than a single header, new line detected. Line 18.

【问题讨论】:

    标签: php post hudson


    【解决方案1】:

    要发布帖子,请使用curl

    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, $yourPostUrl);
    curl_setopt($ch, CURLOPT_POST, 1);
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    // put your headers here
    curl_setopt($ch, CURLOPT_HTTPHEADER, array(
    'User-Agent: Mozilla/5.0 (Windows; U; Windows NT 6.0; en-US; rv:1.9.2.12) Gecko/20101026 Firefox/3.6.12 (.NET CLR 3.5.30729)', 
    'Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8', 
    'Accept-Language: en-us,en;q=0.5'
    ));
    curl_setopt($ch, CURLOPT_POSTFIELDS, $yourXML);
    
    echo $response;
    curl_close($ch); 
    

    【讨论】:

      猜你喜欢
      • 2011-05-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-03-17
      • 2011-08-12
      • 2021-03-05
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多