无法使用Base64获取从客户端发送到servlet的值

时间:2013-01-17 12:38:22

标签: android servlets

这是我的客户端代码 -  byte [] buffer = out.toByteArray();

String ba1=Base64.encodeBytes(buffer);
ArrayList<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>();
nameValuePairs.add(new BasicNameValuePair("image",ba1));
nameValuePairs.add(new BasicNameValuePair("name",fbName));
nameValuePairs.add(new BasicNameValuePair("gender",fbGender));

和http调用的方法 -

public void getServerData(ArrayList<NameValuePair> nameValuePairs)
        throws JSONException, ClientProtocolException, IOException {



    try{

        HttpClient httpclient = new DefaultHttpClient();

        HttpPost httppost = new

        HttpPost(SERVER_URL);

        httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));

        HttpResponse response = httpclient.execute(httppost);

        HttpEntity entity = response.getEntity();

    InputStream is = entity.getContent();

        }catch(Exception e){

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

        }

和服务器端代码到servlet- byte [] image = Base64.decode(“image”); BuffredArray img = ImageIO.read(new ByteArrayInputStream(image)); 但是图像听到的是空的????

在servlet页面上的

我想收到那些参数一个图像,即byte []和两个字符串???我不知道是否可以像这一个图像和两个字符串一样发布数据..但是首先只试验图像我正在考虑例外 显示java.lang.NullPointerException         在java.io.ByteArrayInputStream。(ByteArrayInputStream.java:106)

0 个答案:

没有答案