Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/330.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
way2sms api在java中不工作_Java_Netbeans_Way2sms - Fatal编程技术网

way2sms api在java中不工作

way2sms api在java中不工作,java,netbeans,way2sms,Java,Netbeans,Way2sms,我正在我的web应用程序中使用way2sms api。以前它工作正常,但现在无法发送短信。谁能告诉我什么地方突然出了问题。api是否过时?或者way2sms站点或网关是否存在问题?以下是我编写的一些代码,希望您会发现它很有用 import java.net.*; import java.io.*; public class SmsSender { //Replace your way2sms username and password below static final String

我正在我的web应用程序中使用way2sms api。以前它工作正常,但现在无法发送短信。谁能告诉我什么地方突然出了问题。api是否过时?或者way2sms站点或网关是否存在问题?

以下是我编写的一些代码,希望您会发现它很有用

import java.net.*;
import java.io.*;

public class SmsSender
{
  //Replace your way2sms username and password below
  static final String _userName = "your way2sms username";
  static final String _password = "your way2sms password";
  static final String _url = "http://ubaid.tk/sms/sms.aspx";
  static final String charset = "UTF-8";

  //to build the query string that will send a message
  private static String buildRequestString(String targetPhoneNo, String message) throws UnsupportedEncodingException
  {
    String [] params = new String [5];
    params[0] = _userName;
    params[1] = _password;
    params[2] = message;
    params[3] = targetPhoneNo;
    params[4] = "way2sms";

    String query = String.format("uid=%s&pwd=%s&msg=%s&phone=%s&provider=%s",
        URLEncoder.encode(params[0],charset),
        URLEncoder.encode(params[1],charset),
        URLEncoder.encode(params[2],charset),
        URLEncoder.encode(params[3],charset),
        URLEncoder.encode(params[4],charset)
        );
    return query;
  }

  public static void sendMessage(String reciever, String message) throws Exception
  {
    //To establish the connection and perform the post request
    URLConnection connection = new URL(_url + "?" + buildRequestString(reciever,message)).openConnection();
    connection.setRequestProperty("Accept-Charset", charset);

    //This automatically fires the request and we can use it to determine the response status
    InputStream response = connection.getInputStream();
    BufferedReader br = new BufferedReader(new InputStreamReader(response));
    System.out.println(br.readLine());
  }

  public static void main(String [] args)
    throws Exception
  {
    String testPhoneNo = "9876543210";
    String testMessage = "Sending Messages From java is not too hard";

    sendMessage(testPhoneNo,testMessage);
  }
}

您没有收到任何类型的错误消息或异常吗?我在代码中使用了异常处理,它说无法发送。你想让我发布我的代码吗?如果你只能得到“无法发送”,那你就错了。异常类型是什么?堆栈跟踪是什么?确切的错误消息是什么?你有stacktrace吗?或者“used exception handling”是指您编写了
catch(exception e){System.out.println(“无法发送”);}
?如果是这样,请重新了解异常处理的含义。问题不完整。除非您发布一些相关信息,否则我们如何判断可能突然出现的错误。正确设置您的问题如果way2sms停止工作,您可以尝试其他提供商。提供
api
的人已经转向付费模式,我还没有时间编写替代api。其他一些提供程序可以工作,您需要花一些时间来确定哪些可以工作,哪些不可以。试试这一个,我不确定此网站的所有者是否存储凭据。@nOiAd请检查您发布的链接。它似乎重定向回Way2SMs是的,链接只是重定向请求。