Android AsyncTask从TextView获取param

时间:2015-02-17 01:13:42

标签: json android-asynctask params

我试图按照本教程进行操作: http://www.androidhive.info/2012/01/android-json-parsing-tutorial/

我在我的网址字符串中添加param时遇到问题,我需要将网址设为:

http://api.androidhive.info/contacts?email=params

和params是TextView的内容,我试图采用这样的参数:

String email = emailget.getText().toString();
RequestParams params = new RequestParams();
params.put("email", email);

但是我应该如何以及在哪里使用此参数来确保URL为:

http://api.androidhive.info/contacts?email=params

我需要它,因为在我的Web服务中我的SQL查询是:

SELECT * 
FROM Contact 
WHERE email = ?

我接受这样的查询参数:

@QueryParam("email") String email)

有人可以帮我解决这个问题吗?

提前致谢

2 个答案:

答案 0 :(得分:0)

使用StringBuilder来表示params ....

您能否显示更多代码?

答案 1 :(得分:0)

        // If Your are using a Post Method than add a Params in List Name  value pair.

        List<NameValuePair> params = new ArrayList<NameValuePair>();
        params.add(new BasicNameValuePair("email",xyx@gmail.com));
        params.add(new BasicNameValuePair("password",12345678));


       // Post a request from server

public static  String post(String url,List<NameValuePair> params)
{
    InputStream is = null;
    try {
        DefaultHttpClient httpClient = new DefaultHttpClient();
        HttpPost httpPost = new HttpPost(url);
        httpPost.setEntity(new UrlEncodedFormEntity(params,"UTF-8"));   
        HttpResponse httpResponse = httpClient.execute(httpPost);
        HttpEntity httpEntity = httpResponse.getEntity();
        is = httpEntity.getContent();
    } catch (UnsupportedEncodingException e) {
        e.printStackTrace();
    } catch (ClientProtocolException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    }

    try {
        BufferedReader reader = new BufferedReader(new InputStreamReader(is, "UTF-8"), 8);
        String line = null;
        while ((line = reader.readLine()) != null) {
            respone=line.trim();
        }
        is.close();
    } catch (Exception e) {
        Log.e("Buffer Error", "Error converting result " + e.toString());
    }
    return respone;
}