【发布时间】:2012-03-30 03:05:12
【问题描述】:
我想提出一些自动化测试来验证我的服务器对无效请求 URI 的处理。例如,测试人员可以在 windows 上使用 curl 将其作为他的 url 发送:
http://127.0.0.1/C:\an\incorrect\path\file.txt
我已经在服务器上处理了这个问题,但如果可能的话,我仍然想添加测试。尝试用 HttpClient 来做,但 HttpClient 不喜欢无效字符;)
// Run client
String Url = targetHost + filePath + fileName;
HttpClient httpclient = new DefaultHttpClient();
HttpPost httppost = new HttpPost(Url);
// run test
InputStreamEntity reqEntity = new InputStreamEntity(new FileInputStream(sourceDir.getAbsolutePath() + LusConstants.DIR_SEPERATOR + fileName),-1);
reqEntity.setContentType("binary/octet-stream");
reqEntity.setChunked(chunked);
httppost.setEntity(reqEntity);
httpclient.execute(httppost);
来自 HttpClient 的异常:
aused by: java.net.URISyntaxException: Illegal character in path at index 39: http://127.0.0.1:8080//a/deeper/path/an\incorrect\path\file.txt
at java.net.URI$Parser.fail(Unknown Source)
at java.net.URI$Parser.checkChars(Unknown Source)
at java.net.URI$Parser.parseHierarchical(Unknown Source)
at java.net.URI$Parser.parse(Unknown Source)
at java.net.URI.<init>(Unknown Source)
... 4 more
有什么想法吗?
【问题讨论】:
标签: java httpclient