Java 将Httpsurlconnection与REST一起使用时未找到文件异常;邮政「;功能
当我执行下面的代码时,我遇到了一个问题。 我也有同样的函数,执行rest方法DELETE和PUT,它们在同一配置下工作得很好,但这不是Java 将Httpsurlconnection与REST一起使用时未找到文件异常;邮政「;功能,java,rest,filenotfoundexception,jira-rest-java-api,Java,Rest,Filenotfoundexception,Jira Rest Java Api,当我执行下面的代码时,我遇到了一个问题。 我也有同样的函数,执行rest方法DELETE和PUT,它们在同一配置下工作得很好,但这不是 public void Rest_POST(String cookie) { String urlString = "https://localhost:8443/rest/api/2/version"; HttpsURLConnection urlConnection; String cookie = getCookie(); Str
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
我是java新手,这个解决方案对你有用吗 先给
connection.setDoOutput(true);
connection.setDoInput(true)代码>
if not resolved(若未解决)表示当此案例资源可通过浏览器使用,但不可通过Java代码使用时,使用端口8443的任何其他服务。停止冲突服务或更改服务器的端口号一切正常在方法体中,您将端口指定为2990,但错误消息提到端口8443,哪一个是正确的?请参阅以获取可能的解决方案我已经看到了!没有解决我的问题!还有其他提示吗?哪一行引发异常?如果您使用Firefox的restclient执行POST,服务会返回什么?