Error code 400 when trying to PUT
I try to PUT a file on server. I use HTTPS connection. But I keep getting error code 400 (bad request). Here is the code:
private HttpsURLConnection preparePUTConnection(final String path, int length)
throws MalformedURLException, IOException, ProtocolException {
URL url = new URL(path);
HttpsURLConnection urlConnection = (HttpsURLConnection) url.openConnection();
urlConnection.setHostnameVerifier(DO_NOT_VERIFY);
urlConnection.setDoOutput(true);
String userpassword = username + ":" + password.toString();
String encodedAuthorization = Base64.encodeToString(userpassword.getBytes(), Base64.DEFAULT);
urlConnection.setRequestProperty("Authorization", "Basic "+
encodedAuthorization);
urlConnection.setRequestMethod("PUT");
urlConnection.setRequestProperty("Content-Length", new Integer(length).toString());
urlConnection.connect();
return urlCon开发者_如何转开发nection;
}
精彩评论