我在执行以下代码时遇到问题。我也有执行休息方法 DELETE 和 PUT 的相同功能,它们在相同的配置下工作得很好,但事实并非如此。
public void Rest_POST(String cookie)
{
String urlString = "https://localhost:8443/rest/api/2/version";
HttpsURLConnection urlConnection;
String cookie = getCookie();
String JSONString = "{" +
"\"description\":\"An excellent version\"," +
"\"name\":\"New Version 54164987\"," +
"\"project\":\"zhelp\"" +
"}";
URL url;
OutputStream os;
HttpsURLConnection connection = null;
try {
//this skips the certification check
certificateManager.skipCertificateCheck();
url = new URL(urlString);
connection = (HttpsURLConnection) url.openConnection();
connection.setRequestProperty("Content-Type", "application/json; charset=UTF-8");
connection.setRequestProperty("Content-Language", "en-US");
if(cookie != null) {
System.out.println("Cookie : " + cookie.split(";", 2)[0]);
connection.setRequestProperty("Cookie", cookie.split(";", 2)[0]);
}
connection.setRequestMethod("POST");
connection.setDoOutput(true);
connection.setRequestProperty("Accept", "application/json");
connection.setAllowUserInteraction(true);
os = connection.getOutputStream();
System.out.println("JSONString : " + JSONString);
os.write(JSONString.getBytes());
os.flush();
System.out.println("Connection : " + connection.getURL());
}
这会生成错误 FileNotfound 异常。
Error Message: https://localhost:8443/rest/api/2/version
Cause: java.io.FileNotFoundException: https://localhost:8443/rest/api/2/version