简体   繁体   English

如何从Android应用程序向网页发出请求

[英]How to make requests to a web page from an Android app

There is a web page that has a web service which sends text messages to mobile devices, the service is not my property, I do not know the source code and therefore I do not know how it is handled internally, in that page a form is filled out and When you click on the button to send this, send the form to the server so that the information is processed. 有一个Web页面有一个Web服务,它向移动设备发送文本消息,该服务不是我的属性,我不知道源代码,因此我不知道它是如何在内部处理的,在该页面中一个表单是填写完毕,当您单击按钮发送时,将表单发送到服务器以便处理信息。

I need to pass this web service to an android app to send this type of requests to the page from the app. 我需要将此Web服务传递给Android应用程序,以便从应用程序向页面发送此类请求。

Another doubt that I have the data structure, when clicking with the mouse on the page I have obtained this code that supposedly contains the data structure but I can not find exactly which are the mobile number, the mail account and the message 我有数据结构的另一个疑问,当在页面上用鼠标点击时,我已经获得了这个代码,据说包含数据结构,但我找不到具体的移动号码,邮件帐号和消息

The data structure is: 数据结构是:

server=gsps.ashx
name="to" value="+8707712345678" 
name="reply_email" value="qq@qq.com" 
name="message" value="Hola Mundo"

I have tried to implement this using httpHandler but I do not know how to verify that the message has been sent and I can not capture the server's answer either, someone tell me how to do it. 我试图使用httpHandler实现这个,但我不知道如何验证消息是否已发送,我也无法捕获服务器的答案,有人告诉我该怎么做。

Here the httpHandler class: 这里是httpHandler类:

public class httpHandler {
public String post(String posturl){
    try {
        HttpClient httpclient = new DefaultHttpClient();
        HttpPost httppost = new HttpPost(posturl);
        List<NameValuePair> params = new ArrayList<NameValuePair>();
        params.add(new BasicNameValuePair("to","+870776458585"));
        params.add(new BasicNameValuePair("reply_email","qq@qq.com"));
        params.add(new BasicNameValuePair("message","Hola Mundo!"));
        httppost.setEntity(new UrlEncodedFormEntity(params));
        HttpResponse resp = httpclient.execute(httppost);

        HttpEntity ent = resp.getEntity();/*y obtenemos una respuesta*/
        String text = EntityUtils.toString(ent);
        return text;
    }
  catch(Exception e) { return "error";}
 }
}

Here the MainActivity: 这里是MainActivity:

public class MainActivity extends AppCompatActivity {
private TextView mDumpTextView;
private ScrollView mScrollView;
private EditText mTextoEditor1;
private Button mBotonSend;
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate( savedInstanceState );
    setContentView( R.layout.activity_main );

    mBotonSend = (Button) findViewById( R.id.bt2_SendButton );

    mBotonSend.setOnClickListener( new View.OnClickListener() {
        @Override
        public void onClick(View v) {

            httpHandler handler = new httpHandler();
            String txt = handler.post("https://gsps.ashx");

        }
    } );

  }
}

为什么不加载webview。在布局文件中创建webview并使用所需的URL加载webview。

如果此文本以JSON格式提供,您可以解析它然后您可以使用它。

Html.fromHtml("Your string");

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM