2016-08-12 28 views
1

當前我正在系統上發送證書和從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()); 
+0

身份驗證器用於向網站中的基本身份驗證系統提供憑據。那是你要的嗎 ? 或者您是否只想將憑據作爲Response中的屬性發送? –

回答

1

你指的是什麼配置?你面臨什麼問題?你得到什麼錯誤?

如果您想要在HTTP POST正文中發送一些內容,則應將其寫入URL連接的輸出流。

output.writeBytes(「mytextcontent」);

根據什麼內容類型,你將不得不使用適當的api或輸出流。

+0

謝謝你Rajesh我會讓我的問題更具體,但我發現我的代碼中的問題,並在我的問題中正確編輯它,每個人都可以看到它。 – 404TecZ