2

我在java中使用加密并在php中执行解密。现在,当我将加密参数传递给 url 时,我没有得到正确的响应。这是我的安卓代码。

public static InputStream multipartPOST(String urlStr, 
            Hashtable<String, String> stringParams, 
            Hashtable<String, File> fileParams) throws Exception {URL connectURL = new URL(urlStr);

            conn = (HttpURLConnection)connectURL.openConnection();
            conn.setDoInput(true);
            conn.setDoOutput(true);
            conn.setUseCaches(false);
            //conn.setChunkedStreamingMode(1000*1024);
            int timeout = 10000; 
            conn.setConnectTimeout(timeout);
            conn.setReadTimeout(timeout);
            conn.setRequestMethod("POST");
            conn.setRequestProperty("User-Agent", "RRE");
            conn.setRequestProperty("Connection","Keep-Alive");
            conn.setRequestProperty("Content-Type","multipart/form-data;boundary="+boundary);
            conn.setRequestProperty("Accept-Encoding","gzip");
            conn.connect();

            MessageDigest digester = MessageDigest.getInstance("MD5");
            digester.update(Constants.SALT1.getBytes());

            DataOutputStream dataStream = new DataOutputStream(conn.getOutputStream());
            //DataOutputStream dataStream =new DataOutputStream(new BufferedOutputStream(conn.getOutputStream(), 128000));


            ArrayList<String> stringParamsKeys = Collections.list(stringParams.keys());
            Collections.sort(stringParamsKeys);
            for (String stringParamsKey : stringParamsKeys) {
                String stringParamsValue = stringParams.get(stringParamsKey);
                if(stringParamsValue != null) {
                    writeFormField(dataStream, stringParamsKey, stringParamsValue, digester);
                }
            }

            if(fileParams != null) {
                ArrayList<String> fileParamsKeys = Collections.list(fileParams.keys());
                Collections.sort(fileParamsKeys);
                for (String fileParamsKey : fileParamsKeys) {
                    File fileParamsValue = fileParams.get(fileParamsKey);

                    FileInputStream fileInputStream = new FileInputStream(fileParamsValue);
                    BufferedInputStream bufferedInputStream = new BufferedInputStream(fileInputStream);

                    writeFileField(dataStream, fileParamsKey, fileParamsValue.getName(), "", bufferedInputStream, 
                            fileParamsValue.length(), digester);

                    // final closing boundary line
                    dataStream.writeBytes(twoHyphens + boundary + twoHyphens + CRLF);           
                    bufferedInputStream.close();
                    fileInputStream.close();
                }
            }
            System.out.println(dataStream);
            byte[] messageDigest = digester.digest();
            String md5Hash = Utils.byteArrayToHexString(messageDigest);
            writeFormField(dataStream, "md5Hash", md5Hash, null);

            dataStream.flush();
            dataStream.close();
            dataStream = null;
            try
            {
                InputStream in=conn.getInputStream();

            }
            catch (Exception e) {
                // TODO: handle exception
                Log.d("logexception",e.toString());
            }
            InputStream inputStream = conn.getInputStream();
            System.out.println(inputStream);
            try
            {
                 String contentEncoding = conn.getContentEncoding();
                 Log.d("logexceptio",contentEncoding.toString());
            }
            catch (Exception e) {
                // TODO: handle exception
                Log.d("logexceptionhhhhhhhh",e.toString());
            }
            Log.d("loghi","hiiiiii");
            String contentEncoding = conn.getContentEncoding();

            if (contentEncoding != null && contentEncoding.equalsIgnoreCase("gzip")) {
                System.out.println("gggzzziiippppppp");
                inputStream = new GZIPInputStream(inputStream);
            }

            return inputStream;
            }

在 stingParams 中,我传递了加密参数。我在 conn.getinputstream() 遇到异常。当我在浏览器中传递加密的 url 时,它运行良好。但从android方面我得到了例外。你能告诉我我在做什么错吗?

4

0 回答 0