Json POST适配器HTTP Worklight 6 500服务器错误
我正在尝试在混合Worklight应用程序中注册用户。为此,我使用了一个外部RESTAPI。API说:Json POST适配器HTTP Worklight 6 500服务器错误,json,rest,ibm-mobilefirst,worklight-adapters,Json,Rest,Ibm Mobilefirst,Worklight Adapters,我正在尝试在混合Worklight应用程序中注册用户。为此,我使用了一个外部RESTAPI。API说: 申请方式:邮寄 请求URL:https://${domainservice}/service/plan/${planName}/user?key=${key}&tenantId=${tenantId} 请求头:内容类型:application/json 请求有效负载: { “uid”:“patricia”, “名字”:“帕特里夏”, “姓氏”:“梅奥”, “pic”:“BASE64_编码_图
- 申请方式:邮寄
- 请求URL:https://${domainservice}/service/plan/${planName}/user?key=${key}&tenantId=${tenantId}
- 请求头:内容类型:application/json
- 请求有效负载: { “uid”:“patricia”, “名字”:“帕特里夏”, “姓氏”:“梅奥”, “pic”:“BASE64_编码_图像” }
- uid(必需):用户的uid
- firstName(可选):用户的名字
- lastName(可选):用户的姓氏
- pic(可选):用户图片编码为base64字符串
function RegisterUser(userid) {
var input = {
method : 'post',
path : '/service/plan/App/user',
returnedContentType : 'plain',
headers: {'Content-Type' : 'application/json'},
parameters: {
'key':'e634bc60-0c6eba577258',
'tenantId': 'd93b921d-a56c-a645924fd548'
},
body : {
'contentType' : 'application/json',
'content' : JSON.stringify({
"uid" : userid})
}
};
return WL.Server.invokeHttp(input);
}
我得到了这个错误:
{ "errors": [
],
"info": [
],
"isSuccessful": true,
"responseHeaders": {
"$wsep": "",
"Connection": "Keep-Alive",
"Content-Language": "en-US",
"Content-Type": "text\/html;charset=ISO-8859-1",
"Date": "Wed, 30 Jul 2014 14:47:27 GMT",
"Transfer-Encoding": "chunked",
"X-Backside-Transport": "FAIL FAIL",
"X-Client-IP": "199.127.32.67",
"X-Global-Transaction-ID": "48515650",
"X-Powered-By": "Servlet\/3.0"
},
"responseTime": 357,
"statusCode": 500,
"statusReason": "Internal Server Error",
我觉得我的设计很奇怪
标题:{'Content-Type':'application/json'}
但在回应中,它看起来像
“内容类型”:“文本/html;字符集=ISO-8859-1”
我还想指出一些我已经尝试过的事情:
- returnedContentType:'plain'-->它被设置为plain,因为如果我将它设置为json,我将得到一个json解析错误
- 我也试过了
然后是“内容”:有效负载var payload = "{\'uid\': \'"+userid+"\'}"; payload = payload.toString();
- 使用浏览器的RESTClient,一切正常
- 我尝试使用http端口80、http端口2080以及HTTPS443
- 我还尝试在标题中写入主机
您可以在Eclipse的“首选项->运行->TCP/IP监视器”中进行设置 您可能需要添加主机头。我曾多次看到它解决了类似的问题。例如,如果您试图连接以将下面的标题添加到headers属性中
headers: {
Host: 'www.server.com'
}
我终于发现了错误。Worklight中存在一个缺陷,查询参数被删除并放入请求正文中,因此REST服务不会接收key&tenantId。这是最终的工作代码解决方案。无论如何,感谢您的快速回答:)
function RegisterUser(userid) {
var payload = '{"uid": \"'+userid+'\"}';
var input = {
method : 'post',
path : '/service/plan/App/user?key=e630-db87-4803-bc45-57725c&tenantId=d9348af-a56c-a645924fd54e',
returnedContentType : 'application/json',
headers: {'Content-Type' : 'application/json'},
body : {
'contentType' : 'application/json',
'content' : payload.toString()
}
};
return WL.Server.invokeHttp(input);
}