1

currently im working on a system to send credentials and a XML selected from a TextPane or from a file, i would get the path to it with a FileChooser. my question is if someone knows an explanation how to configure the HttpsUrlConnection. I understand that its done by .setRequestProperty or .addRequestProperty but the server is throwing this error

ActDelivery_HTTP.Utils:getEncodingFromPartner(/0/1) ActDelivery_HTTP.Inbound:receiveXML(/0/0/0) UTF-8

I have researched a lot but I'm not that good in java. That's why I'm asking if someone could explain the configuration of a 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()); 
1
  • Authenticator is used for providing credentials to Basic Authentication System incorporated in websites. Is that what you want ? Or do you just want to send the credentials as a property in the Response ? Commented Aug 12, 2016 at 7:36

1 Answer 1

1

What configuration you are referring to? And what issue you are facing? And what error you are getting?

If you want to sent some content in the HTTP POST body, you should write that to the output stream of the URL connection.

output.writeBytes("mytextcontent");

Depending what the content type, u will have to use appropriate api or output stream.

Sign up to request clarification or add additional context in comments.

1 Comment

Thank u Rajesh i would made my question more specific but i found the problem in my code and edited it properly in my question that everyone can see it.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.