通过 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)){ }
这里判断的的时候为空。
1 junbaor 2017-04-01 11:42:31 +08:00 |
![]() | 2 zorui OP 现在确定的就是 php 中 php.ini 配置 post_max_size 是大于要上传的文件的。 |
4 hcymk2 2017-04-01 12:36:51 +08:00 抓个包和与表单提交的对比下先. |
![]() | 5 ijustdo 2017-04-01 12:46:52 +08:00 呵呵 不要查肯定是 post 文件的时候 Content-Type 不对的呢 ^_^ |
![]() | 6 zorui OP Content-Type 都是 multipart/form-data |
![]() | 7 zorui OP |
![]() | 8 zorui OP |
![]() | 9 8355 2017-04-01 15:27:47 +08:00 ![]() php://input 接收二进制流应该可以的. 试试吧 |
10 hcymk2 2017-04-01 16:21:13 +08:00 ![]() |
![]() | 11 zorui OP |