java httpurlconnection http put错误400
我几乎一字不差地从this example from stackoverflow获取HTTP PUT代码——我试图将一个XML文件放入ExistDB rest接口,但我从URLConnection getResponseCode()接收到“400 Bad Request”值,却完全看不到远程服务器记录的任何内容,就好像从未发送过请求一样
URL target = new URL( "http://domain.com:8080/exist/rest/db/collection/doc.xml" )
HttpURLConnection uc = (HttpURLConnection) target.openConnection();
uc.setDoOutput(true);
uc.setDoInput(true);
uc.setRequestMethod("PUT");
uc.setConnectTimeout(CONNECT_TIMEOUT); // timeouts are both 2000L
uc.setReadTimeout(READ_TIMEOUT); //ms
uc.setRequestProperty("Content-type", "text/xml");
// basic Auth s.getLogin() already recorded as username:pwd format
String auth = new String( Base64.encodeBase64String( s.getLogin().getBytes() ));
auth = auth.replaceAll("\n",""); // sun bug_id 6459815
uc.setRequestProperty("Authorization", "Basic " + auth );
uc.connect(); // tried moving this to after the body section below
PrintWriter body = new PrintWriter(uc.getOutputStream());
InputStream sml = smlStream(this.pathid);
StringBuilder xml = new StringBuilder( new Scanner(sml).useDelimiter("\\A").next());
body.print(xml);
body.close();
uc.disconnect(); // appears to make no difference
加州大学。getResponseCode()现在的值为400
如果我在相同的URL和正文中的相同xml文件(curl-v-u uname:pw-T file.xmlhttp://domain.com:8080/exist/rest/db/collection/doc.xml)上使用curl,从相同的机器在相同的用户ID下发送请求,那么文档将按照预期进行并返回201响应。另一方面,Java版本(使用openjdk7)什么都不做
这些通话顺序对吗?有没有办法获得更多关于请求语法无效原因的信息
共 (0) 个答案