将数据发送到网站-Android

一个网站,其中有几个下拉框.我制作了一个Android应用程序,用于从网站中提取值.现在网站上有一个搜索框,在网站上,我们可以从框中选择选项,然后按Submit,然后根据所选的选项给出结果.我需要在我的应用中执行相同的操作.
需要帮助.谢谢

解决方法:

要将数据发布到网站,您已经向其发送了HTTP POST请求.您可以将要发送的数据放入数组,然后将其发送到PHP脚本.

您必须弄清楚您的String是通过哪个ID发送到服务器的.在我的示例中,它是your_1和your_2.每个网站都不同.所有新的浏览器都可以在开发人员控制台中读取内容.

public void postData() {
// Create a new HttpClient and Post Header
HttpClient httpclient = new DefaultHttpClient();
HttpPost httppost = new HttpPost("http://www.yoursite.com/script.PHP");

try {
    // Add your data
    List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(2);
    nameValuePairs.add(new BasicNameValuePair("your_1", "data 1"));
    nameValuePairs.add(new BasicNameValuePair("your_2", "data 2"));
    httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));

    // Execute HTTP Post Request
    HttpResponse response = httpclient.execute(httppost);

} catch (ClientProtocolException e) {
    // Todo Auto-generated catch block
} catch (IOException e) {
    // Todo Auto-generated catch block
}

发送完之后,您必须获得响应,您可以使用StringBuilder读出该响应.

private StringBuilder inputStreamToString(InputStream is) {
String line = "";
StringBuilder total = new StringBuilder();

// Wrap a BufferedReader around the InputStream
BufferedReader rd = new BufferedReader(new InputStreamReader(is));

// Read response until the end
while ((line = rd.readLine()) != null) { 
    total.append(line); 
}

// Return full string
return total;
}

现在您有了响应,您可以使用RegEx强调您的特殊文字.这有点棘手,但是this可以帮助您.

相关文章

Android性能优化——之控件的优化 前面讲了图像的优化,接下...
前言 上一篇已经讲了如何实现textView中粗字体效果,里面主要...
最近项目重构,涉及到了数据库和文件下载,发现GreenDao这个...
WebView加载页面的两种方式 一、加载网络页面 加载网络页面,...
给APP全局设置字体主要分为两个方面来介绍 一、给原生界面设...
前言 最近UI大牛出了一版新的效果图,按照IOS的效果做的,页...