开发者

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;
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜