Android 应用程序将简单的表单发送到 Web 服务并获取短信作为回报

发布于 2024-10-30 07:54:58 字数 1562 浏览 1 评论 0原文

我正在尝试用简单的形式编写一个Android应用程序。用户将向服务器发送一个字符串,并收到一条短信,其中包含相同的字符串+“谢谢!”。

我了解 Java,但我更擅长 C#。我确实设法将字符串发送到网络服务。

在 Android 客户端上:

public void sendFeedback(View button) { 
    final EditText nameField = (EditText) findViewById(R.id.EditTextName);  
    String name = nameField.getText().toString();  
    postData(name);
}

public void postData(String name) {
    // Create a new HttpClient and Post Header
    HttpClient httpclient = new DefaultHttpClient();
    HttpPost httppost = new HttpPost("http://localhost:53811/WinnerSite/WebService.asmx?op=WriteToDB");

    try {
        // Add your data
        List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(2);
        nameValuePairs.add(new BasicNameValuePair("json", name));
        //  nameValuePairs.add(new BasicNameValuePair("stringdata", "AndDev is Cool!"));
        httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));

        // Execute HTTP Post Request
        HttpResponse response = httpclient.execute(httppost);
        System.out.println(response.getFirstHeader(getPackageName()));
    } catch (IOException e) {
        // TODO Auto-generated catch block
    }
}

Web 服务非常薄弱:

[WebMethod]
public string WriteToDB(string json)
{
    return "Hello World "+ json;
}

我使用 Visual-Studio 内置的服务器服务运行 Web 服务。 应用程序背后的代码正确获取了字符串,但代码从未收到该字符串。有人知道可能是什么问题吗?

在下一阶段,我无法找到从我的网络服务 SMS 发送至以下以色列运营商之一的 SMS 电子邮件网关:

  • Orange(又名合作伙伴)
  • Cellcom

有人可以帮助我找到该网关吗?

I'm trying to write an android application with a simple form. The user will send a string to a server and will get an SMS back with the same string + "thank you!".

I know Java but I'm more fluent in C#. I did manage to send the string to the web-service.

On Android Client:

public void sendFeedback(View button) { 
    final EditText nameField = (EditText) findViewById(R.id.EditTextName);  
    String name = nameField.getText().toString();  
    postData(name);
}

public void postData(String name) {
    // Create a new HttpClient and Post Header
    HttpClient httpclient = new DefaultHttpClient();
    HttpPost httppost = new HttpPost("http://localhost:53811/WinnerSite/WebService.asmx?op=WriteToDB");

    try {
        // Add your data
        List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(2);
        nameValuePairs.add(new BasicNameValuePair("json", name));
        //  nameValuePairs.add(new BasicNameValuePair("stringdata", "AndDev is Cool!"));
        httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));

        // Execute HTTP Post Request
        HttpResponse response = httpclient.execute(httppost);
        System.out.println(response.getFirstHeader(getPackageName()));
    } catch (IOException e) {
        // TODO Auto-generated catch block
    }
}

Web-Service is pretty slim:

[WebMethod]
public string WriteToDB(string json)
{
    return "Hello World "+ json;
}

I ran the web-service with Visual-Studio built in server service.
The code behind the application got the string properly, but the code never recieved the string. Does someone has an idea what could be the problem?

the next phase, I cannot find the SMS email gate to SMS from my web-service SMS to one of the following Israeli operators:

  • Orange (a.k.a Partner)
  • Cellcom

Can someone help me find that gate?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

姐不稀罕 2024-11-06 07:54:58

尝试使用

JSONObject json = new JSONObject();
json.but("name",name)

并在服务器中使用

json_encode("name than you ");

可能对您有帮助的消息发送消息

try to use

JSONObject json = new JSONObject();
json.but("name",name)

and in the server send a message by using

json_encode("name than you ");

that may help you

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文