GET发出URLConnection请求。代码在这里

java.net.URL url = new java.net.URL(requestUrl);
        URLConnection urlConnection = url.openConnection();
        is = new BufferedInputStream(urlConnection.getInputStream());


获取java.io.FileNotFoundException而请求的网址正确。我认为可能是https ssl证书问题。如果其他人遇到此问题并解决了,请更新。

最佳答案

对参数进行编码以创建用于请求的URL。不支持
  参数值中的字符可能会导致异常,也可能是空格。


    String url = "http://url.com";
    String charset = "UTF-8";  // Or in Java 7 and later, use the constant: java.nio.charset.StandardCharsets.UTF_8.name()
    String param1 = "value1";
    String param2 = "value2";
    // ...

    String query = String.format("param1=%s&param2=%s",
         URLEncoder.encode(param1, charset),
         URLEncoder.encode(param2, charset));

    URLConnection connection = new URL(url + "?" + query).openConnection();
    connection.setRequestProperty("Accept-Charset", charset);
    InputStream response = connection.getInputStream();
// ...


Courtsey

关于java - FileNotFoundException与Urlconnection获取请求,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/33772367/

10-12 01:56