我想连接到一个短信网关。我找到了以下代码。
public void smsSender(String username, String password, String to,
String text) throws IOException {
try {
String data = "username=" + username + "&password=" + password
+ "&to=" + to + "&text=" + text;
URL url = new URL("https://sendsms.abc.com:1010/sms.php");
HttpURLConnection urlc = (HttpURLConnection) url.openConnection();
urlc.setRequestMethod("POST");
urlc.setDoOutput(true);
urlc.setRequestProperty("Content-type",
"application/x-www-form-urlencoded");
BufferedWriter br = new BufferedWriter(new OutputStreamWriter(
urlc.getOutputStream()));
br.write(data);
br.flush();
BufferedReader rd = new BufferedReader(new InputStreamReader(
urlc.getInputStream()));
String line;
while (null != ((line = rd.readLine()))) {
output = line;
System.out.println(output);
}
rd.close();
} catch (Exception e) {
e.printStackTrace();
}
}
当我尝试使用此方法进行连接时,Eclipse 会发送一条错误消息。
无法找到到所请求目标的有效认证路径
我试图访问的服务器正在使用自签名证书。我是这个领域的新手。我怎么解决这个问题。提前致谢 :)