未通过大宗短信网站在手机上发送短信

问题描述 投票:0回答:2

我正在尝试通过批量短信发送网站在手机上发送短信。我正在尝试使用以下代码通过Java API发送短信。它没有显示任何错误,但是没有发送消息。

 String urlParameters="usr=username &pwd=1234 &ph=9015569447 &text=Hello";
 //String request = "http://hapi.smsapi.org/SendSMS.aspx?";
 String request="http://WWW.BULKSMS.FELIXINDIA.COM/send.php?";
try{                        
URL url = new URL(request); 
HttpURLConnection connection = (HttpURLConnection) url.openConnection();           
connection.setDoOutput(true);
connection.setDoInput(true);
connection.setInstanceFollowRedirects(false); 
connection.setRequestMethod("POST"); 


connection.setRequestProperty("Content-Type", "application/x-www-form-urlencoded"); 
connection.setRequestProperty("charset", "utf-8");
connection.setRequestProperty("Content-Length", "" +         Integer.toString(urlParameters.getBytes().length));
  connection.setUseCaches (false);

DataOutputStream wr = new DataOutputStream(connection.getOutputStream ());
wr.writeBytes(urlParameters);

    wr.flush();
wr.close();
connection.disconnect();
}
catch(Exception ex)
{
 System.out.print(ex);
}
java http-headers connection sms-gateway
2个回答
1
投票

您应在写入流后检查响应代码,以了解正在发生的事情:

int rc = connection.getResponseCode();
if(rc==200)
{
    //no http response code error
    //read the result from the server
    rd = new BufferedReader(new InputStreamReader(connection.getInputStream()));
    sb = new StringBuilder();
    //get the returned data too
    returnString=sb.toString();
}
else
{
    System.out.println("http response code error: "+rc+"\n");
}

((从here中粘贴的代码)

NEVER这样做:

catch(Exception ex)
{
    System.out.print(ex);
}

这对您的健康有害:下一个调试您的代码将给您一个沉重的负担,让您发现它!

任一

catch(Exception ex)
{
    ex.printStackTrace();
}

catch(Exception ex)
{
    LOG.error("Something went wrong (adequate error message here please)", ex);
}

必须完成!


1
投票

我在请求参数URL之间看到一些空格:

 String urlParameters="usr=username&pwd=1234&ph=9015569447&text=Hello";

这可能是问题。

© www.soinside.com 2019 - 2024. All rights reserved.