使用HttpClient上传文件,断点调试卡住,没法往下进行的问题

须要使用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

相关文章
相关标签/搜索