FileNotFoundException 与 Urlconnection 获取请求
FileNotFoundException with Urlconnection Get Request
用 URLConnection
执行 GET
请求。代码在这里
java.net.URL url = new java.net.URL(requestUrl);
URLConnection urlConnection = url.openConnection();
is = new BufferedInputStream(urlConnection.getInputStream());
获得 java.io.FileNotFoundException
而请求 url 是正确的。我认为这可能是 https ssl 证书问题。如果其他人遇到此问题并已解决,请更新。
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.
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¶m2=%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
用 URLConnection
执行 GET
请求。代码在这里
java.net.URL url = new java.net.URL(requestUrl);
URLConnection urlConnection = url.openConnection();
is = new BufferedInputStream(urlConnection.getInputStream());
获得 java.io.FileNotFoundException
而请求 url 是正确的。我认为这可能是 https ssl 证书问题。如果其他人遇到此问题并已解决,请更新。
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.
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¶m2=%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