iServer 8C RESTAPI发布服务失败

0 投票
使用以下代码调用rest api发布地图服务,发布失败,请帮们看下原因。

<script type="text/javascript">
        var host = "http://localhost:8090";
        //令牌有效期是一年
        var token = "QTPQVdeePnFEusfoGz8y7uhfCRCZGlv5PaFy_tBEtNmRwp6UO_tXrV3eSC5IwbXg_Q0LRjOb3khRjZABmud9nw..";

        function AutoOracleDwgToSV() {//自动更新oracle地图服务
            var commit=getcommit();
            var method="post";
            var uri = host + "/iserver/manager/workspaces.rjson?token=" + token;
            var async=false;
            var user="";
            var password="";
            //以下示例请求体
            //"servicesTypes": ["RESTMAP", "RESTDATA", "WMS111"], "workspaceConnectionInfo": "../samples/data/World/World.sxwu"
            commit.open(method,encodeURI(uri),async,user,password);
            commit.setRequestHeader("Content-Type", "application/x-www-form-urlencoded; charset=UTF-8");

            //设置请求条件
            var requestbody = {};
            requestbody.servicesTypes=["RESTMAP", "RESTDATA", "WMS111"];
            requestbody.workspaceConnectionInfo={
                server="ORCL_10.6.1.0",
                username="sys",
                password="sa",
                type="ORACLE",
                database="",
                name="workspaceoracle",
                driver=null        
            };
           
            commit.send(toJSON(requestbody));//发送请求
            var response = json_parse(commit.responseText, null);
            console.log(requestbody,response,"发布复合数据集请求体及响应");
            var container = document.getElementById('container');
            container.innerHTML +=toJSON(response)+"<br>";
        }
    </script>
11月 16, 2016 分类:  1981次浏览 | 用户: cherubicwing 初出茅庐 (23 分)

1个回答

0 投票
看下请求返回状态,检查token是否有效,可以直接测试:
http://${serverhost}/iserver/manager/workspaces.rjson?token=${yourtoken}
${}换成相应内容
认证失败是返回401状态吗,errorMsg会显示失败原因,需要认证或者无效令牌
11月 16, 2016 用户: 毛瑞 名扬四海 (1,780 分)
试下不要用localhost呢?

我把localhost换成我自己本机的ip,修改为http://10.7.1.34:8090,还是提示“工作空间连接信息错误”

是这个原因:
requestbody.workspaceConnectionInfo={
                server="ORCL_10.6.1.0",
                username="sys",
                password="sa",
                type="ORACLE",
                database="",
                name="workspaceoracle",
                driver=null        
            };
workspaceConnectionInfo属性改成字符串,分号隔开...,看我上面抓的请求,workspaceConnectionInfo不是个对象,只是个字符串...

没明白您的意思。我发布本地服务也提示这个错误。

本地服务是这样写的:

requestbody.servicesTypes = ["RESTMAP"];
requestbody.workspaceConnectionInfo = ["F:/TestData/发布服务数据/kqcgislocal.smwu"];

你说的改成字符串是什么意思?能举个例子吗?

我是参考帮助文档写的。
请放大看前面的截图,请求体比如:
{"workspaceConnectionInfo": "server=orcl203;username=test;password=test;type=ORACLE;database=;name=testWorkSpace;driver=null",其他参数}
...