解决方案 »

  1.   

    服务器是大php写的.
    而我自己用servlet简单写了个验证. 发现我的上传文件名字是没问题的.  是XX.mp3或xx.jpg的
      

  2.   

    private void uploadFile(final String uploadUrl){
          new Thread(){
           public void run() {
           String end = "\r\n";
               String twoHyphens = "--";
               String boundary = "******";
               try
               {
                 URL url = new URL(uploadUrl);
                 HttpURLConnection httpURLConnection = (HttpURLConnection) url
                     .openConnection();
                 httpURLConnection.setChunkedStreamingMode(128 * 1024);// 128K
                 // 允许输入输出流
                 httpURLConnection.setDoInput(true);
                 httpURLConnection.setDoOutput(true);
                 httpURLConnection.setUseCaches(false);
                 // 使用POST方法
                 httpURLConnection.setRequestMethod("POST");
                 httpURLConnection.setRequestProperty("Connection", "Keep-Alive");
                 httpURLConnection.setRequestProperty("Charset", "UTF-8");
                 httpURLConnection.setRequestProperty("Content-Type",
                     "multipart/form-data;boundary=" + boundary);             DataOutputStream dos = new DataOutputStream(
                     httpURLConnection.getOutputStream());
                 dos.writeBytes(twoHyphens + boundary + end);
                 dos.writeBytes("Content-Disposition: form-data; name=\""+uploadedfile+"\"; filename=\""
                     + srcPath.substring(srcPath.lastIndexOf("/") + 1)
                     + "\""
                     + end);
                 dos.writeBytes(end);
                 
                 FileInputStream fis = new FileInputStream(srcPath);
                 byte[] buffer = new byte[8*1024]; // 8k
                 int count = 0;
                 // 读取文件
                 while ((count = fis.read(buffer)) != -1)
                 {
                   dos.write(buffer, 0, count);
                 }
                 fis.close();             dos.writeBytes(end);
                 dos.writeBytes(twoHyphens + boundary + twoHyphens + end);
                 dos.flush();             InputStream is = httpURLConnection.getInputStream();
                 InputStreamReader isr = new InputStreamReader(is, "utf-8");
                 BufferedReader br = new BufferedReader(isr);
                 String result = br.readLine();
                 System.out.println(result);
                 handler.sendEmptyMessage(1);
                 dos.close();
                 is.close();           } catch (Exception e)
               {
                 e.printStackTrace();
               }
           };
          }.start();
        }这个是拼装方法