Joke Collection Website - Blessing messages - How does java create a simple http interface?
How does java create a simple http interface?
& lt! Simulate HTTP calls and write one. Artoz. Artoz. Artoz. Action. Order. Sending SMS operation; Import com.atoz.util.springcontextutil;
The public class SmsHTTPServer extends HTTP servlet {private static final long serialversionuid =1l;
The public void doget (http servlet request, HttpServletResponse response) throws ServletException, ioexception {response. setcontenttype ("text/html; charset = utf-8“); request . setcharacterencoding(“utf-8“); response . setcharacterencoding(“utf-8“); PrintWriter out = response . getwriter(); string content = request . getparameter(“content“); //String content = new string (request.getparameter ("content")). getBytes(“iso-8859- 1“)、“utf-8“); string mobiles = request . getparameter(“mobiles“); string business code = request . getparameter(“business code“); string business type = request . getparameter(“business type“); if(content = = null | |“。 equals(content)| | content . length()& lt; = 0){ system。 Out.println ("HTTP call failed, parameter content cannot be empty, program exits"); } else if(mobiles = = null | |“。 equals(mobiles)| | mobiles . length()& lt; = 0){ system。 Out.println ("HTTP call failed, parameter mobiles cannot be empty, and the program exits"); } else {/* SendSMSServiceImpl send = new SendSMSServiceImpl(); */SendSMSAction sendSms =(SendSMSAction)springcontextutil . get bean(“sendSms“); SendSms.sendSms (content, mobile phone, service code, service type); System. out.println ("-HTTP call succeeded-"); } out . close(); }
Public void dopost (HTTP Servlet Request, HttpServletResponse) throws ServletException, IOException {this.doGet (request, response); } }
3. Call the http interface
string content =“test“; content = URL encoder . encode(content,“utf-8“); string URL =“http://localhost:8 180/atoz _ 20 14/http server? content =“+content+“& amp; mobiles = 1530 1895007“; URL httpTest please try {httptest = new URL (URL); BufferedReader intry { in = new buffered reader(new InputStreamReader(httptest . openstream())); String inputline = null String Resultmsg = null//Get the return information of xml string while((input line = in. readline ())! = null)if(result msg! = null){ result msg+= input line; } else { resultMsg = inputLine} in . close(); } catch(malformedurexception e){ e . printstacktrace(); }} catch(io exception e){//TODO automatically generated catch block e.printstacktrace (); }
Typing is not easy, hope to adopt, thank you.
- Previous article:What should I do if I flash back after receiving the text message and opening it?
- Next article:Unicom broadband or Great Wall broadband?
- Related articles
- Some English expressions on the phone
- Birthday wishes for my girlfriend
- Being cheated by Haier's consumer finance, can you not pay back the high interest?
- I just bought a number card here. Why did I receive a text message reminding me that I owed more than 100 yuan for electricity?
- Receive a trust message from a stranger
- Touching words that can save marriage
- Sad jokes about missing your lover
- How to turn up the sound of Meizu mobile phone
- Bank of Communications Student Credit Card Parents Withdraw SMS
- How to contact your ex-boyfriend skillfully