[英]Calling soap webservice using wsdl, username and password in java
[英]calling API that have username and password in java
大家好,我正在嘗試使用此代碼連接到具有用戶名和密碼的 API
try {
URL url = new URL("https://url?UserName=username&Password=password");
Connection = (HttpURLConnection) url.openConnection();
//Request setup
Connection.setRequestMethod("GET");
Connection.setConnectTimeout(5000);
Connection.setReadTimeout(5000);
int status = Connection.getResponseCode();
System.out.println(status);
} catch (MalformedURLException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
如果您嘗試以這種方式對您的網址進行編碼。
HttpURLConnection connection = (HttpURLConnection)
new URL("https://url?UserName"+URLEncoder.encode(username, "UTF-8")+"&Password="+URLEncoder.encode(password, "UTF-8"))
.openConnection();
connection.setRequestMethod("GET");
connection.setRequestProperty("Content-Type", "application/json");
InputStream is = connection.getInputStream();
BufferedReader rd = new BufferedReader(new InputStreamReader(is,"UTF-8"));
//rest your code
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.