0

更新时间条目: http ://www.redmine.org/projects/redmine/wiki/Rest_TimeEntries#Updating-a-time-entry 结果始终为 404

我正在使用 Redmine 3.4.6.stable 并且正在使用:PUT /time_entries/[id].xml

其他操作,例如:创建时间条目正在工作。

此外,Delete 不起作用,我尝试使用 JSON 作为 XML 的替代品,但响应相同。

然后我删除了这样的扩展:/time_entries/[id],我得到了 422,但响应给了我一个完整的 HTML 页面:

无效的表单真实性令牌。

我不是 Ruby/Rails 开发人员,但在 routes.rb 中我可以看到:

match '/time_entries/:id', :to => 'timelog#destroy', :via => :delete, :id => /\d+/

这是唯一的条目:/time_entries/:id

因此这意味着位于 http://www.redmine.org/projects/redmine/wiki/Rest_TimeEntries#Updating-a-time-entry的文档 已过时,并且没有更新时间条目的终点。这个对吗?

我还在 Redmine 提交了一张票: http ://www.redmine.org/issues/31288 但我想我会更快地得到答案/帮助。

这是我用来更新问题的 Groovy 代码:

def baseUrl = new URL("${Config.host}/time_entries/${timeEntry.key}.xml?key=${Config.redmineKey}")
new HTTPBuilder(baseUrl).request(Method.PUT, ContentType.XML) {
    body = "<time_entry><id>9956</id><project_id>25</project_id><issue_id>${timeEntry.key}</issue_id><spent_on>${spentOnDate}</spent_on><hours>${new Date(timeEntry.value.toInteger()).format("HH:mm")}</hours><activity_id>9</activity_id><comments></comments></time_entry>"
    response.success = { resp, xml ->
        println "Success! ${resp.status}"
    }
    response.failure = { resp ->
        println "Request failed with status ${resp.status}"
        def outputStream = new ByteArrayOutputStream()
        resp.entity.writeTo(outputStream)
        def errorMsg = outputStream.toString('utf8')
        println errorMsg
    }
}
4

1 回答 1

0

下面的代码适用于 nodejs 并使用 xml 格式:

const http = require('http')

var body = ' <?xml version="1.0" ?>' +
           '<time_entry><id>1</id><issue_id>1</issue_id><spent_on>2019-02-02</spent_on><hours>9.0</hours></time_entry>';

var postRequest = {
    host: "localhost",
    path: "/time_entries/1.xml",
    port: 3000,
    method: "PUT",
    headers: {
        'Content-Type': 'text/xml',
        'X-Redmine-API-Key': '95228de814b46d8980447c00591460598990d469',
        'Content-Length': Buffer.byteLength(body)
    }
};

var buffer = "";

var req = http.request( postRequest, function( res )    {

   console.log( res.statusCode );
   var buffer = "";
   res.on( "data", function( data ) { buffer = buffer + data; } );
   res.on( "end", function( data ) { console.log( buffer ); } );

});

req.on('error', function(e) {
    console.log('problem with request: ' + e.message);
});

req.write( body );
req.end();

确保正确配置 postRequest 参数,例如 X-Redmine-API-key 路径、主机、端口和方法...

于 2019-05-14T08:04:49.027 回答