• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • Rob Spoor
  • Bear Bibeault
Saloon Keepers:
  • Jesse Silverman
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • Al Hobbs
  • salvin francis

send data in java application through post method

 
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Dear developers,
I wanted to send data in a java application to a servlet which the servlet has a post() method to extract the data. My problem is the whole thing just doesn't work. Below is my codes and please kindly advise me on my problem.
--------------------------------------------------
import java.io.*;
import java.net.*;
public class StarhubSms{

private String mobile = "90278850";
private String msg = "success";
private String host = "SHCORP";

public void startSms(){

try{
URL url = new URL("http://www.starhub.com.sg/servlet/SMSServlet");
URLConnection conn = url.openConnection();
conn.setDoOutput(true);
conn.setUseCaches (false);
conn.setDefaultUseCaches (false);
conn.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");

String message = "host="+URLEncoder.encode("SHCORP") + "&mobile="+URLEncoder.encode("90278850") +"&msg="+URLEncoder.encode("she");

BufferedWriter out =
new BufferedWriter( new OutputStreamWriter( conn.getOutputStream() ) );

System.out.println(message+"\r\n");
out.write(message);
out.flush();

out.close();

System.out.println("Message sent!!");

}
catch(Exception e){}

}
}
-------------------------------------------------
Warmest regards,
Franco
 
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I tried to build your sting in my browser and send the message but the service returned the message:
Error. The file was not found. (servlet name = null**%20Message%20Not%20Sent,%20Check%20Mobile%20Number%20**)
This would cause me to think that there is a) some problem with the service for that number, b) there are more or fewer parameters required to send a message, or c) there was something wrong with what I entered into the browser location bar.
My first step would be to print out the entire URL including the parameters to standard out and paste that string in your browser to see what error message the server is returning to you. If the message sends okay, then you know it is your code, if not, you need to fix something in what you are sending the server.
Hope this helps!
 
Author and all-around good cowpoke
Posts: 13078
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
As you may know, SOAP sends messages like this, a real pain to debug without special tools. I wrote a debugging tool that lets you capture the actual text of the message as sent, modify it, etc. - it is available for download at:
http://www.lanw.com/books/javasoap/default.htm
at the bottom of the page.
Bill
 
You showed up just in time for the waffles! And this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic