Http post with basic authorization don't work in java
Posted
by glebreutov
on Stack Overflow
See other posts from Stack Overflow
or by glebreutov
Published on 2010-06-02T15:14:02Z
Indexed on
2010/06/02
15:34 UTC
Read the original article
Hit count: 222
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();
© Stack Overflow or respective owner