0

此发布请求转到连接到我的数据库的 php 页面,该页面查询文本字段“名称”中的任何内容。当我知道它们不为空时,附加到结果的字符串始终为空。我想念什么?

public void onClick(View v) {
    URI website = null;
    HttpResponse response = null;
    BufferedReader in = null;
    InputStream is = null;
    String result = "hello";
    JSONObject jArray = null;


    HttpClient client = new DefaultHttpClient();

    try {
        website = new URI("http://fakesite.com");
    } catch (URISyntaxException e) {
        e.printStackTrace();
    }

    HttpGet getRequest = new HttpGet();
    getRequest.setURI(website);

    HttpPost postRequest = new HttpPost(website);


    try {

        List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(2);
        nameValuePairs.add(new BasicNameValuePair("name", name.toString() ));
        postRequest.setEntity(new UrlEncodedFormEntity(nameValuePairs));

        response = client.execute(postRequest);

        HttpEntity entity = response.getEntity();
        is = entity.getContent();

        results.append(" got response");
    } catch (ClientProtocolException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    }

    try {
        BufferedReader reader = new BufferedReader(new InputStreamReader(is,"iso-8859-1"),8);
        StringBuilder sb = new StringBuilder();
        String line = null;

        while ((line = reader.readLine()) != null) {
            sb.append(line + "\n");
        }

        is.close();
        result=sb.toString();

        results.append(result);

    } catch (UnsupportedEncodingException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    }

}
4

1 回答 1

0

nameValuePairs.add(new BasicNameValuePair("name", name.toString() ));

name.toString() 中的名称是什么。你在哪里初始化名称对象?

于 2012-11-21T05:23:06.760 回答