java 短信接口_用Java调用短信接口给手机发送短信怎么写代码??接口已经有了,是一个url....

展开全部

那你要做的就是向这个URL发送数据就好,给个例子:

public   class  Httptest1  {

8

9       public   static   void  main(String[] args)  {

10

11         URL url  =   null ;

12         HttpURLConnection conn  =   null ;

13         OutputStream outStream  =   null ;

14         InputStream inStream  =   null ;

15

16           try   {

17             url  =   new  URL( " http://219.233.89.7:8090/cgi-bin/mailinterface ");

18             conn  =  (HttpURLConnection) url.openConnection();

19             conn.setDoOutput( true );

20             conn.setDoInput( true );

21

22             String sendXml  =   " <?xml  version=\ " 1.0 \ "  encoding=\ " UTF - 16 \ " ?>SigMailCommand SYSTEM \ " SigMail.dtd\ "> " ;  // XML数据

23              sendXml  +=   " test.com.cn " ;

24             sendXml  +=   " admin " ;

25

26             outStream  =  conn.getOutputStream();

27

28              // 准备通636f707962616964757a686964616f31333332626161过CONN对象写入XML数据

29              BufferedWriter bw  =   new  BufferedWriter( new  java.io.OutputStreamWriter(outStream,

30              " UTF-16 " ));

31             bw.write(sendXml);

32             bw.flush();

33             bw.close();

34

35              // DataOutputStream dataOutStream = new DataOutputStream(outStream);

36              // dataOutStream.writeChars(xml);

37              // dataOutStream.flush();

38              // dataOutStream.close();

39

40

41              // 准备通过CONN对象读取返回的XML数据

42

43             inStream  =  conn.getInputStream();

44             StringBuffer returnXml  =   new  StringBuffer( "" );

45             BufferedReader rd  =   new  BufferedReader( new  InputStreamReader(inStream,

46                      " UTF-16 " ));

47               for  (String line  =   null ; (line  =  rd.readLine())  !=   null ;)  {

48                 returnXml.append(line);

49             }

50             System.out.println(returnXml.toString());

51             rd.close();

52          }   catch  (IOException ex)  {

53             ex.printStackTrace();

54          } finally {

55               try   {

56                  if  (outStream  !=   null )

57                     outStream.close();

58                  if  (inStream  !=   null )

59                     inStream.close();

60                  if  (conn  !=   null )

61                     conn.disconnect();

62              }   catch  (IOException e)  {

63                  //  TODO 自动生成 catch 块

64                  e.printStackTrace();

65             }

66         }

67

68     }

69

70 }

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值