當前我正在系統上發送證書和從TextPane
或從文件中選擇的XML,我將通過FileChooser
獲取路徑。我的問題是如果有人知道如何配置HttpsUrlConnection
的解釋。據我所知,它通過.setRequestProperty
或.addRequestProperty
完成,但服務器拋出這個錯誤配置Java HttpsURLConnection
ActDelivery_HTTP.Utils:getEncodingFromPartner(/ 0/1) ActDelivery_HTTP.Inbound:receiveXML(/ 0/0/0) UTF- 8
我已經研究了很多,但在java中我並不擅長。這就是爲什麼我問是否有人可以解釋HttpsUrlConnection
的配置。
try {
Authenticator.setDefault (new Authenticator() {
protected PasswordAuthentication getPasswordAuthentication() {
return new PasswordAuthentication (textUser.getText(), textPass.getText().toCharArray());
}
});
URL myurl = new URL(httpsURL);
HttpsURLConnection con = (HttpsURLConnection)myurl.openConnection();
con.setRequestMethod("POST");
con.setRequestProperty("Content-length", URLEncoder.encode(textXML.getText(), "UTF-8"));
con.setRequestProperty("Content-Type","text/xml; charset=UTF-8");
con.setRequestProperty("Https-Agent", "");
con.setRequestProperty("Content", URLEncoder.encode(textXML.getText(), "UTF-8"));
con.setRequestProperty("Dest-Port", "443"); // I'm not sure how to add the xml as request
con.setDoOutput(true); // out of a text box or just the file at all
con.setDoInput(true);
DataOutputStream output = new DataOutputStream(con.getOutputStream());
output.writeBytes(textXML.getText());
output.close();
DataInputStream input = new DataInputStream(con.getInputStream());
for(int c = input.read(); c != -1; c = input.read())
System.out.print((char)c);
input.close();
System.out.println("Resp Code:"+con .getResponseCode());
System.out.println("Resp Message:"+ con .getResponseMessage());
身份驗證器用於向網站中的基本身份驗證系統提供憑據。那是你要的嗎 ? 或者您是否只想將憑據作爲Response中的屬性發送? –