Hello.
I'm trying to send SMS via http xml post.
The sequence of action is this:
    1) Connect to Kannel. ( Method=POST,  Content-Type=text/xml)
    2) Open outpus stream, send xml, close stream.
    3) Open inpud stream, read Kannels reply, close stream.
    4) Close connection.
I send the prepared xml string to Kannel and read an answer. In first time kannel returns "Sent." message. Then I run my program one more time - Connection refused error accrues then trying to get input stream for reading data from kannel (step 3). If running program once again everything is OK. Next time - Connection refused. And so on. In both cases SMS delivers succesfully.
And if reading connection responce code even after step 4, it is "202" (processing has not been completed).
What I am doing wrong ?
 
Here is my Java code:
URL url - kannel url
String xml - xml string to send.
 
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
connection.setRequestMethod( "POST" );
connection.setRequestProperty( "Content-Type", "text/xml" );
connection.setRequestProperty( "Content-length", "" + xml.length());
connection.connect();
 
DataOutputStream outputStream = new DataOutputStream( connection.getOutputStream() );
outputStream.writeBytes( xml );
outputStream.close();
     
InputStream is = connection.getInputStream();
int b = -1;
StringBuffer buf = new StringBuffer();
do{  b = is.read();
       if( b!= -1 )  buf.append((char)b); }while (b != -1);
is.close();
connection.disconnect();
 

Reply via email to