我在执行下面的代码时遇到了问题。我也有同样的功能,执行rest方法删除和把那些是伟大的工作与相同的配置,但这不是。
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
1条答案
按热度按时间z31licg01#
我是java新手,这个解决方案对你有用吗
第一次给予
connection.setDoOutput(true); connection.setDoInput(true);
如果未解析,则表示通过浏览器(而不是java代码)可以使用此案例资源时,使用端口8443的任何其他服务。停止冲突服务或更改服务器的端口号一切正常