【发布时间】:2016-08-11 14:40:37
【问题描述】:
我正在开发一个离子混合移动应用程序并尝试在 JSON-RPC 服务中发布数据,但我收到“500 internal server error”
var req = {
url: 'http://192.118.1.214:8080/remote/json-rpc',
headers: {
'content-type': 'application/json;charset=utf-8',
'cache-control': 'no-cache, no-store, must-revalidate, max-age=0'
},
data: { jsonrpc: "2.0", id: 2, method: "HDAccess/getDevices", params: [null] }
}
$http(req).then(function (res) { alert(res); return res; },
function (er) { alert(er); });
这是来自 webconsole 的请求详细信息。我使用 chrome CORS 插件来避免“CORS”问题
Request URL:http://192.118.1.214:8080/remote/json-rpc
Request Method:OPTIONS
Status Code:500 Internal Server Error
Remote Address:192.118.1.214:8080
Response Headers
view source
cache-control:no-cache, no-store, must-revalidate, max-age=0
content-length:810
content-type:text/html; charset=UTF-8
date:Tue, 01 Mar 2016 08:00:50 GMT
pragma:no-cache
Request Headers
view source
Accept:*/*
Accept-Encoding:gzip, deflate, sdch
Accept-Language:en-GB,en-US;q=0.8,en;q=0.6
Access-Control-Request-Headers:accept, cache-control, content-type
Access-Control-Request-Method:GET
Connection:keep-alive
Host:192.118.1.214:8080
Origin:http://evil.com/
Referer:http://localhost:8100/
User-Agent:Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/49.0.2623.112 Safari/537.36
我在 POSTMAN 扩展中使用了相同的 url 和 post 方法并得到了工作,但在上面的代码中不起作用。
在下面找到 POSTMAN 输入
我有三个疑惑:
1.为什么上述请求详情中没有提到数据。
2.为什么方法显示为“选项”,但我使用的是“POST”方法
3.为什么它不能通过代码工作,但在 chrome POSTMAN 扩展客户端中工作正常
请指导我解决这个问题。
【问题讨论】:
标签: javascript angularjs ionic-framework xmlhttprequest