Java - Put Request

时间:2015-10-14 20:17:22

标签: java httpurlconnection

我试图执行"PUT"但没有任何反应,我也没有发现任何异常。

以下是我尝试的内容:

String destinationUrl = 'http://stash.myDomain.com/rest/api/1.0/projects/myProj/permissions/users?name=myUser&permission=PROJECT_WRITE';

URL url = null;
try {
    url = new URL(destinationUrl)
} catch (MalformedURLException exception) {
    exception.printStackTrace();
}
HttpURLConnection httpURLConnection = null;
DataOutputStream dataOutputStream = null;

try {
    String userpass = STASH_USERNAME + ":" + STASH_PASSWORD;
    String basicAuth =  "Basic " + converter.printBase64Binary(userpass.getBytes());
    httpURLConnection = (HttpURLConnection) url.openConnection();
    httpURLConnection.setRequestMethod("PUT");
    httpURLConnection.setDoInput(true);
    httpURLConnection.setDoOutput(true);
    httpURLConnection.setRequestProperty("Authorization", basicAuth)
    //httpURLConnection.setRequestProperty("Content-Type", "application/json");

    dataOutputStream = new DataOutputStream(httpURLConnection.getOutputStream());
    dataOutputStream.writeBytes("Hello");
} catch (IOException excepption) {
    excepption.printStackTrace();
} finally {
    if (dataOutputStream != null) {
        try {
            dataOutputStream.flush();
            dataOutputStream.close();
        } catch (IOException exception) {
            exception.printStackTrace();
        }
    }
    if (httpURLConnection != null) {
        httpURLConnection.disconnect();
    }
}

知道我该怎么办?

0 个答案:

没有答案