4

R を使用してデータを JIRA プロジェクトに POST しようとしていますが、エラーが発生し続けます: リクエストが正しくありません。最初は、私が作成した JSON 形式に違いないと思いました。そのため、JSON をファイルに書き込み、コンソールから curl コマンドを実行すると (以下を参照)、POST は正常に機能しました。

curl -D- -u fred:fred -X POST -d @sample.json -H "Content-Type: application/json" http://localhost:8090/rest/api/2/issue/

これは私のRコードに問題をもたらします。RCurl postForm で何が間違っているのか教えてもらえますか?

ソース:

library(RJSONIO)
library(RCurl)

x <- list (
  fields = list(
  project = c(
     c(key="TEST")
  ),
  summary="The quick brown fox jumped over the lazy dog",
  description = "silly old billy",
  issuetype = c(name="Task")
 )
)


curl.opts <- list(
  userpwd = "fred:fred",
  verbose = TRUE,
  httpheader = c('Content-Type' = 'application/json',Accept = 'application/json'),
  useragent = "RCurl"           
)

postForm("http://jirahost:8080/jira/rest/api/2/issue/",
     .params= c(data=toJSON(x)),
     .opts = curl.opts,
     style="POST"
)

rm(list=ls()) 
gc()

応答の出力は次のとおりです。

* About to connect() to jirahost port 80 (#0)
* Trying 10.102.42.58... * connected
* Connected to jirahost (10.102.42.58) port 80 (#0)
> POST /jira/rest/api/2/issue/ HTTP/1.1
User-Agent: RCurl
Host: jirahost
Content-Type: application/json
Accept: application/json
Content-Length: 337

< HTTP/1.1 400 Bad Request
< Date: Mon, 07 Apr 2014 19:44:08 GMT
< Server: Apache-Coyote/1.1
< X-AREQUESTID: 764x1525x1
< X-AUSERNAME: anonymous
< Cache-Control: no-cache, no-store, no-transform
< Content-Type: application/json;charset=UTF-8
< Set-Cookie: atlassian.xsrf.token=B2LW-L6Q7-15BO- MTQ3|bcf6e0a9786f879a7b8df47c8b41a916ab51da0a|lout; Path=/jira
< Connection: close
< Transfer-Encoding: chunked
< 
* Closing connection #0
Error: Bad Request
4

1 に答える 1