如何使用java代码使用http请求在Android中发送短信

时间:2016-11-06 15:19:29

标签: java android api http sms

我想使用Android应用程序发送短信。为此,我引用了以下网站。

  1. ozekisms.com
  2. Java Sms Example
  3. How To Make HTTP POST Request To Server
  4. 从我注册的以下网站和使用该API网址开始,我提出了该请求 http://websms.24x7sms.com/
    http://www.24x7sms.com/downloads/24x7sms_http_api2.pdf

    为此,我使用了以下代码。

    protected void sendSMS(){
    
        Log.d("in","booking sms function");
        String nm1        = name.getText().toString();
        String ara1       = area.getSelectedItem().toString();
        String add1       = address.getText().toString();
        String mob1       = mobile.getText().toString();
    
        String message1   = "Name:"+ nm1 + "\n" + "Area:" + ara1 + "\n" + "Address:" + add1 + "\n"
                + "Mobile:" + mob1;
    
    
    
        BufferedReader reader = null;
    
        // Defined URL  where to send data
        String requesturl = "http://smsapi.24x7sms.com/api_2.0/SendSMS.aspx?APIKEY=********" +
                "MobileNo=+91**********&SenderID=SMSMsg&Message=You%20have%20new%20booking%20fro%20(variable%20please%20collect%20from%20them." +
                "ServiceName=TEMPLATE_BASED";
    
        try {
    
            URL url = new URL(requesturl);
            HttpURLConnection huc = (HttpURLConnection)url.openConnection();
            huc.setRequestMethod("POST");
            Log.d("after connection open",huc.getResponseMessage());
    
            Log.d("RESPONSE FROM SERVER", huc.getResponseMessage());
    
    
            }
    

    运行程序后,我在logcat窗口中收到以下消息。

    11-06 20:14:57.830 6513-6513/com.******.*******.********* D/in: booking sms function
    11-06 20:14:58.555 6513-6513/com.******.*******.********* D/after connection open: OK
    11-06 20:14:58.556 6513-6513/com.******.*******.********* D/RESPONSE FROM SERVER: OK
    

    但我从未收到有关特定暴徒号码的消息。请帮助我。

    先谢谢你......

0 个答案:

没有答案