简体   繁体   English

FileNotFoundException与Urlconnection获取请求

[英]FileNotFoundException with Urlconnection Get Request

Doing GET request with URLConnection . 使用URLConnection GET请求。 code is here 代码在这里

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

getting java.io.FileNotFoundException whereas requested url is correct. 获取java.io.FileNotFoundException而请求的网址正确。 i think it may be https ssl certificate issue. 我认为可能是https ssl证书问题。 if anyone else got this issue and resolved please update. 如果其他人遇到此问题并解决了,请更新。

Encode your parameter to create an URL for request.Unsupported character in parameter value may cause to exceptions it can be a white space also. 对您的参数进行编码以创建请求的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 考特西

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM