发布到Atlassian Confluence api时出现意外的grunt-http错误 [英] Unexpected grunt-http error when posting to Atlassian Confluence api

查看:262
本文介绍了发布到Atlassian Confluence api时出现意外的grunt-http错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

试图在Atlassian wiki上创建一个wiki页面。我之前使用的是python脚本,这段代码没有任何问题:

  data = json.dumps({type: data:testData,title:postTitle,space:{key:EB},body:{storage:{value:content,representation :storage}}})
r = requests.post(https://estech.atlassian.net/wiki/rest/api/content/,data = data,headers = headers,auth =(confluenceLogin ['username'],confluenceLogin ['password']))

现在我试着使用以下grunt任务配置:

  http:{
atlassianwiki:{
options:{
uri:atlassianURL +/ wiki / rest / api / content /,
标题:{Content-Type:application / json},
auth:{
user :confluencelogin,
pass:confluencepass
},
方法:POST,
body:JSON.stringify(wi kijson)
}
}
}



  wikijson = {
type:page,
data:testData ,
title:testtitle,
space:{key:EB},
body:{
storage:{
value:< p>测试发布< / p>,
representation:storage
}
}
}

运行此任务时出现以下错误:

 致命错误:500 {statusCode:500,message:java.io.EOFException:由于输入结束而无法映射到Object的内容} 

经过一番Google-fu,我发现有些人声称他们通过在卷曲中添加--post302来解决这个问题命令行。但我真的不知道或理解这是如何适用于此。



谢谢,我希望这是有道理的。

解决方案

我在使用合流REST API时遇到了问题,在我的情况下,问题出现在内容类型头文件中,但您似乎已经拥有了它。

我没有'尝试创建新页面,但更新现有的一个
Confluence API对我来说似乎有点神奇,所以我只是在这里离开这里我开始工作之前必须做的所有步骤,也许其中一个会帮助你。 / p>

function composeRequest(method){
var auth = new Buffer(user +': '+ pass).toString('base64');
var request = {
host:'confluence.myserver.com',
port:443,
contentType:application / json; charset = utf-8,
'path':path,
method:method || GET,
标题:{
'授权':'基本'+验证,
'内容类型':'application / json'
},
rejectUnauthorized:false,
requestCert:true,
agent:false
};


退货请求;
}

而且它出现了页面更新请求JSON必须包含


  • pageId(即使它在路径中,您需要重复它)

  • type

  • title

  • 版本(这很奇怪,但你应该设置它,0或1,我不记得)



而且当你的数据被填充时,你应该将它转换为字符串,并填充请求中的content-type字段!

  data = JSON.stringify(data); 
request.headers ['Content-Length'] = data.length;
https.request(request,respondHandler)




Attempting to create a wiki page on an Atlassian wiki. I previously was using a python script and this code worked no problem:

data = json.dumps({"type":"page", "data":"testData", "title":postTitle,"space":{"key":"EB"}, "body":{"storage":{"value": content,"representation":"storage"}}})
r = requests.post("https://estech.atlassian.net/wiki/rest/api/content/", data=data, headers=headers, auth=(confluenceLogin['username'], confluenceLogin['password']))

Now I'm trying to use the following grunt task configuration:

    http: {
        atlassianwiki: {
            options: {
                uri: atlassianURL + "/wiki/rest/api/content/",
                headers: {"Content-Type": "application/json"},
                auth: {
                    "user": confluencelogin,
                    "pass": confluencepass
                },
                method:"POST",
                body: JSON.stringify(wikijson)
            }
        }
    }

with wikijson looking like:

wikijson = {
            "type": "page",
            "data": "testData",
            "title": "testtitle",
            "space": {key:"EB"},
            "body": {
                "storage": {
                    "value": "<p>testing posting</p>",
                    "representation": "storage"
                }
            }
        }

And I get the following error when this task runs:

Fatal error: 500 {"statusCode":500, "message":"java.io.EOFException: No content to map to Object due to end of input"}

Upon a bit of google-fu, I found that some people claim they fixed this by adding "--post302" to their curl command line. But I don't really know or understand how that applies here.

Thanks and I hope this makes sense.

解决方案

i was fighting with confluence REST API and in my case the problem was in content-type header, but you seem to have it already.
I didn't try to create new page but to update existing one Confluence API seemed a little bit magic to me, so i just leave here all steps i had to make before it started working, maybe one of them will help you.

function composeRequest(method) {
  var auth = new Buffer(user + ':' + pass).toString('base64');
  var request = {
  host: 'confluence.myserver.com',
  port: 443,
  contentType: "application/json; charset=utf-8",
  'path': path,
  method: method || "GET",
  headers: {
    'Authorization': 'Basic ' + auth,
    'Content-Type': 'application/json'
  },
  rejectUnauthorized: false,
  requestCert: true,
  agent: false
};


  return request;
}

And it appeared that page update request JSON MUST contain

  • pageId (even it is inside path, you need to repeat it)
  • type
  • title
  • version (it's weird, but you should set it. 0 or 1, i don't remember)

And when your data if filled, you should convert it to string and fill content-type field in your request!

data = JSON.stringify(data);
request.headers['Content-Length'] = data.length;
https.request(request, respondHandler)

这篇关于发布到Atlassian Confluence api时出现意外的grunt-http错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆