Unable to get values seding from client to servlet using Base64

两盒软妹~` 提交于 2019-12-25 09:34:50

问题


this is my client side code- 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));

and the i call method for http post-

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());

        }

and the server side code onto servlet- byte[] image=Base64.decode("image"); BuffredArray img = ImageIO.read(new ByteArrayInputStream(image)); But the image hear is null????

on the servlet page i want to recieve those parameters one image i.e byte[] and two strings ???i dont know if it is possible to post data like this one image and two strings..but experimenting with only image first i am geting Exception java.lang.NullPointerException at java.io.ByteArrayInputStream.(ByteArrayInputStream.java:106)

来源:https://stackoverflow.com/questions/14379315/unable-to-get-values-seding-from-client-to-servlet-using-base64

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!