通过 java httpclient 模拟表单上传 PHP/5.3.3 上 empty($_FILES) 为空,通过 html 代码直接表单提交就是正常的。 PHP/5.4.40 也是可以的
httpclient4.5.2 模拟请求的代码:
InputStreamBody streamBody = new InputStreamBody(inputStream, contentType, fileData.getFilename()); MultipartEntityBuilder multipartEntityBuilder = MultipartEntityBuilder.create(); multipartEntityBuilder.addPart("file", streamBody); for (String key : params.keySet()) { multipartEntityBuilder.addPart(key, new StringBody((String) params.get(key), ContentType.TEXT_PLAIN)); } HttpEntity entity = multipartEntityBuilder .setMode(HttpMultipartMode.BROWSER_COMPATIBLE) .setContentType(MULTIPART_FORM_DATA_UTF8) .setCharset(Consts.UTF_8).build(); httpPost.setEntity(entity); HttpResponse respOnse= HttpClientBuilder.create().build().execute( httpPost); String resultStr = IOUtils.toString(response.getEntity().getContent()); php 中接收的:
if(!empty($_FILES)){ } 这里判断的的时候为空。
