如何在android中向服务器发送大字符串?

时间:2014-08-17 04:17:23

标签: php android http-post

我想从android向服务器发送大字符串,我可以用这个方法发送小字符串

        InputStream is;
        String name = "Name";
        String str = "LargeString";

        ArrayList<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>();

        nameValuePairs.add(new BasicNameValuePair("name", name));
        nameValuePairs.add(new BasicNameValuePair("encoded", str));

        try {

            HttpClient httpclient = new DefaultHttpClient();
            HttpPost httppost = new
            HttpPost("http://192.168.1.101/test/insert.php");
            httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
            HttpResponse response = httpclient.execute(httppost);
            HttpEntity entity = response.getEntity();
            is = (InputStream) entity.getContent();


        } catch (Exception e) {

            Log.e("log_tag", "Error in http connection " + e.toString());

        }

使用此代码我可以发送小字符串,但不能大字符串。 请帮帮我。

谢谢。

1 个答案:

答案 0 :(得分:0)

使用HttpUrlConnection

您可以参考here