https连接java_如何从Java应用程序设置Https连接
我使用
java創(chuàng)建桌面應(yīng)用程序,此應(yīng)用程序使用API??.為了保證與API的通信,我們得到了他們支持使用HTTPS的通知.請指導(dǎo)我如何從
Java客戶端設(shè)置https連接.
API具有此功能,表明它可以選擇安全連接:
private String getUrlAddress(XmlRequest request) {
// determine if this is a secure connection
String url = this.ssl ? "https://" : "http://";
// determine service endpoint based on type of class/request passed in
if( request.getClass() == MessageRequest.class) {
url += ClockWorkSmsService.SMS_URL;
}
else {
url += ClockWorkSmsService.CREDIT_URL;
}
return url;
}
這段代碼讓我覺得“請求”將是我當(dāng)前的網(wǎng)址或服務(wù)器,因此我將在我這邊設(shè)置https連接.
Clockworksms API包裝器:
import com.clockworksms.*;
public class DemoSms
{
public static void main(String[] args)
{
try
{
ClockWorkSmsService clockWorkSmsService = new ClockWorkSmsService("apikey");
SMS sms = new SMS("441234567890", "Hello World");
ClockworkSmsResult result = clockWorkSmsService.send(sms);
if(result.isSuccess())
{
System.out.println("Sent with ID: " + result.getId());
}
else
{
System.out.println("Error: " + result.getErrorMessage());
}
}
catch (ClockworkException e)
{
e.printStackTrace();
}
}
}
總結(jié)
以上是生活随笔為你收集整理的https连接java_如何从Java应用程序设置Https连接的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: sqlite插入时间字段_sqlite
- 下一篇: 全栈工程师薪水_2020 Java 全栈