请求的路由[/ sms]尚未在Spark中被映射为接受:[null]

时间:2019-05-13 16:37:48

标签: android twilio twilio-api

INFO spark.http.matching.MatcherFilter-请求的路由[/ sms]尚未在Spark中被映射为接受:[空]

下面我显示了我的代码。引发错误。我尝试了不同的解决方案,但不能解决我的问题。

Android代码:

      public class MainActivity extends AppCompatActivity {

      @Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    submitbt = findViewById(R.id.submitbt);
    submitbt.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
      post("https://c7xxxxxx.ngrok.io/sms", new  Callback(){
                            @Override
                            public void onFailure(Call call, IOException e) {
                                e.printStackTrace();
                            }
                            @Override
                            public void onResponse(Call call, Response response){
                                runOnUiThread(new Runnable() {
                                    @Override
                                    public void run() {
                                        Toast.makeText(getApplicationContext(),"SMS Sent!",Toast.LENGTH_SHORT).show();
                                    }
                                });
                            }
                        });
                    } catch (Exception e) {
                        e.printStackTrace();
                    }
                  });
                 }
               });
            }
    Call post(String url, Callback callback) {
    RequestBody formBody = new FormBody.Builder()
            .add("To", "98xxxxxxxx")
            .add("Body", "Hello It's Working")
            .build();
    Request request = new Request.Builder()
            .url(url)
            .post(formBody)
            .build();
    Call response = mClient.newCall(request);
    response.enqueue(callback);
    return response;
}
 }

API调用:

     public class SMSBackend
       {
public static void main(String[] args) {
    TwilioRestClient client = new TwilioRestClient.Builder("ACxxxxxxxxxxxxxxxxxxxxxxxxxxxxx", "36xxxxxxxxxxxxxxxxxxxxxxxxxxxxx").build();

    post("/sms", (req, res) -> {
        String body = req.queryParams("Body");
        String to = req.queryParams("To");
        String from = "+120xxxxxxxx";

        Message message = new MessageCreator(
                new PhoneNumber(to),
                new PhoneNumber(from),
                body).create(client);

        return message.getSid();
    });
}
    }

请帮助我解决此问题。预先感谢

0 个答案:

没有答案