views:

89

answers:

1

This code work without exceptions but post request does not work. What I do wrong? I use Java 1.6, JBoss 4.2.3

    String xml = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" +
            "<message><service id=\"210\"/><to>+"+phone+"</to>" +
            "<body content-type=\"text/plain\">"+message+"</body></message>";

    String userPassword = "login:password";
    URL url = new URL(ksGateUrl);
    URLConnection urlc =  url.openConnection();

    urlc.setDoOutput(true);
    urlc.setUseCaches(false);
    urlc.setAllowUserInteraction(false);
    urlc.setRequestProperty("Authorization", 
            "Basic " + new sun.misc.BASE64Encoder().encode (userPassword.getBytes()));


    OutputStreamWriter wr = new OutputStreamWriter(urlc.getOutputStream(), "UTF-8");
    wr.write(xml);
    wr.flush();
+2  A: 
String userPassword = "login:password";
URL url = new URL(ksGateUrl);
// URLConnection urlc =  url.openConnection();
URLConnection urlc =  new URLConnection(url);

urlc.setDoOutput(true);
urlc.setUseCaches(false);
urlc.setAllowUserInteraction(false);
urlc.setRequestProperty("Authorization", 
        "Basic " + new sun.misc.BASE64Encoder().encode (userPassword.getBytes()));

urlc.connect();
PeterMmm