我试图使用JSOUP将一些json对象发布到Saiku Server中。这是我的代码。
Response document1 = Jsoup
.connect(
"http://localhost:8080/saiku/rest/saiku/admin/datasources/")
.header("Content-Type", "application/json")
.data(testJson.toJSONString())
.ignoreContentType(true)
.referrer("http://localhost:8080/")
.cookie("JSESSIONID", res.cookie("JSESSIONID"))
.userAgent(
"Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/50.0.2661.94 Safari/537.36")
.method(Method.POST).timeout(10000).execute();
我得到像这样的错误
Errorjava.lang.IllegalArgumentException: Must supply an even number of key value pairs .
我搜寻了许多网站,但找不到相应的解决方案。有人可以澄清一下吗。提前致谢。我在这里附上我的代码,
我使用requestBody()发布JSON对象。requestBody()方法仅在JSOUP 1.9.1 jar中可用,并且我在下面发布了代码供您参考。
// JSON Object
JSONObject testJson = new JSONObject();
testJson.put("connectionname", "drinkss");
testJson.put("jdbcurl", "jdbc:mysql://localhost/drink");
testJson.put("schema", "datasources/dr.xml");
testJson.put("driver", "com.mysql.jdbc.Driver");
testJson.put("username", "root");
testJson.put("password", "211218");
testJson.put("connectiontype", "MONDRIAN");
// For Posting datasource into server
Response document1 = Jsoup
.connect(
"http://localhost:8080/saiku/rest/saiku/admin/datasources/")
.header("Content-Type", "application/json")
.requestBody(testJson.toString())
.data(testJson)
.ignoreContentType(true)
.referrer("http://localhost:8080/")
.cookie("JSESSIONID", res.cookie("JSESSIONID"))
.userAgent(
"Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/50.0.2661.94 Safari/537.36")
.method(Method.POST).timeout(10000).execute();
System.out.println("post successfully....."
+ testJson.toJSONString());
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句