From 64bc543df25c83524c1177d8ec51f1d76119ba86 Mon Sep 17 00:00:00 2001 From: Redkale <22250530@qq.com> Date: Sun, 14 Aug 2016 16:14:51 +0800 Subject: [PATCH] --- src/org/redkale/net/http/MultiContext.java | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/org/redkale/net/http/MultiContext.java b/src/org/redkale/net/http/MultiContext.java index bf3c1c626..8cacf7c09 100644 --- a/src/org/redkale/net/http/MultiContext.java +++ b/src/org/redkale/net/http/MultiContext.java @@ -113,10 +113,14 @@ public final class MultiContext { final String disposition = readLine(); //if (debug) System.out.println("disposition=" + disposition); if (disposition.contains("; filename=\"")) { //是上传文件 - String contentType = readLine(); + String contentType = ""; + //读掉HTTP Header和空白行 通常情况下Content-Type后面就是内容,但是有些特殊情况下后面会跟其他如Content-Length: xxx等HTTP header,所以需要循环读取 + String rl; + while (!(rl = readLine()).isEmpty()) { + if (rl.startsWith("Content-Type:")) contentType = rl.substring(rl.indexOf(':') + 1).trim(); + } //if (debug) System.out.println("file.contentType=" + contentType); - contentType = contentType.substring(contentType.indexOf(':') + 1).trim(); - readLine(); //读掉空白行 + String name = parseValue(disposition, "name"); String filename = parseValue(disposition, "filename"); if (filename == null || filename.isEmpty()) { //没有上传