-1

谁能告诉我这段代码有什么问题,它返回语法错误。任何人都可以修复它吗?

dos.writeBytes(twoHyphens + boundary + lineEnd); 
dos.writeBytes("Content-Disposition: form-data; name="uploaded_file";filename=""
+ fileName + """ + lineEnd);'

第二部分在 catch 它返回错误。请检查这个:

runOnUiThread(new Runnable() {
public void run() {
String msg = "File Upload Completed.\n\n See uploaded file here : \n\n"
             +http://www.androidexample.com/media/uploads/"
             +uploadFileName;
messageText.setText(msg);
Toast.makeText(UploadToServer.this, "File Upload Complete.",Toast.LENGTH_SHORT).show();
      }
    });                
  }    
fileInputStream.close();
dos.flush();
dos.close();
} catch (MalformedURLException ex) {
  dialog.dismiss();  
  ex.printStackTrace();
runOnUiThread(new Runnable() {
 public void run() {
 messageText.setText("MalformedURLException Exception : check script url.");
 Toast.makeText(UploadToServer.this, "MalformedURLException",Toast.LENGTH_SHORT).show();

 }
 });
 Log.e("Upload file to server", "error: " + ex.getMessage(), ex);  
 } catch (Exception e) {
 dialog.dismiss();  
 e.printStackTrace();
 runOnUiThread(new Runnable() {
 public void run() {
  messageText.setText("Got Exception : see logcat ");
  Toast.makeText(UploadToServer.this, "Got Exception : see logcat ",Toast.LENGTH_SHORT).show();
  }});
 Log.e("Upload file to server Exception", "Exception : " + e.getMessage(), e);  
  }
  dialog.dismiss();       
  return serverResponseCode;              
 } // End else block
} 
}
 @Override
 public boolean onCreateOptionsMenu(Menu menu) {
 getMenuInflater().inflate(R.menu.upload_to_server, menu);
 return true;
 }
}
4

1 回答 1

0
 dos.writeBytes("Content-Disposition: form-data; name=\"uploaded_file\";\"filename=\""+ fileName + "\"" + lineEnd);

双引号内不使用双引号,您需要输入“\”(反斜杠)

于 2013-08-23T09:48:43.103 回答