須要使用HttpClient上傳一張圖片,結果斷點調試到 java
public void uploadFile(String filePath) throws Exception{ PostMethod filePost = new UTF8PostMethod(url); try{ String fileName = filePath.substring(filePath.lastIndexOf("/")+1); FilePart fp = new FilePart("file",fileName, new File(filePath)); MultipartRequestEntity mrp= new MultipartRequestEntity(new Part[]{fp}, filePost.getParams()); filePost.setRequestEntity(mrp); HttpClient client = new HttpClient(); client.getHttpConnectionManager().getParams().setConnectionTimeout(5000); int status = client.executeMethod(filePost); if (status == HttpStatus.SC_OK){ System.out.println("上傳成功");// 上傳成功 }else{ throw new CcsException("HttpClient.upload.url.fail"); } }catch (Exception ex){ throw new CcsException((ex instanceof CcsException) ? ((CcsException)ex).getPrompt(): "HttpClient.upload.fail", ex);//上傳文件失敗! }finally{ filePost.releaseConnection(); } }
HttpClient client = new HttpClient();這句的時候,直接卡住了,F6沒法下一步。url
解決:直接按F8跳過,OK!
spa
緣由:本人的經理覺得,須要往前臺傳數據,所以只能跳過!調試
Ok!!!
code