Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
516 views
in Technique[技术] by (71.8m points)

通过java httpclient模拟表单上传 , PHP/5.3.3 上 empty($_FILES) 接收时为空

通过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)){
    } 

这里判断的的时候为空。


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
等待大神答复

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

2.1m questions

2.1m answers

60 comments

57.0k users

...