diff options
author | ray-pixar <pixar@chmail.ir> | 2015-09-10 19:19:15 +0430 |
---|---|---|
committer | ray-pixar <pixar@chmail.ir> | 2015-09-10 19:19:15 +0430 |
commit | 6bb048c991a52c0b974bd4a316579f0a622a70ec (patch) | |
tree | a46258645f3647431c60379335d217445a22ab81 /src/net/HttpParser.cpp | |
parent | a4954856e680b85eebdcfa5dddf5c9baf8102077 (diff) |
Fix for send files using multipart/form
Diffstat (limited to 'src/net/HttpParser.cpp')
-rw-r--r-- | src/net/HttpParser.cpp | 18 |
1 files changed, 11 insertions, 7 deletions
diff --git a/src/net/HttpParser.cpp b/src/net/HttpParser.cpp index a2d9108..3ea95ec 100644 --- a/src/net/HttpParser.cpp +++ b/src/net/HttpParser.cpp @@ -63,16 +63,16 @@ string HttpParser::generateRequest(const Url& url, const vector<HttpReqArg>& arg string bondary = generateMultipartBoundary(args); if (bondary.empty()) { result += "Content-Type: application/x-www-form-urlencoded\r\n"; - requestData = generateWwwFormUrlencoded(args); + requestData = generateWwwFormUrlencoded(args); } else { result += "Content-Type: multipart/form-data; boundary="; result += bondary; - result += "\r\n"; + result += "\r\n"; requestData = generateMultipartFormData(args, bondary); - } + } - result += "Content-Length: "; - result += lexical_cast<string>(requestData.length()); + result += "Content-Length: "; + result += lexical_cast<string>(requestData.length()); result += "\r\n\r\n"; result += requestData; } @@ -86,8 +86,11 @@ string HttpParser::generateMultipartFormData(const vector<HttpReqArg>& args, con result += bondary; result += "\r\nContent-Disposition: form-data; name=\""; result += item.name; + if(item.isFile) { + result += "\"; filename=\"" + item.fileName; + } result += "\"\r\n"; - if (item.isFile) { + if (item.isFile) { result += "Content-Type: "; result += item.mimeType; result += "\r\n"; @@ -96,6 +99,7 @@ string HttpParser::generateMultipartFormData(const vector<HttpReqArg>& args, con result += item.value; result += "\r\n"; } + result += "--" + bondary + "--"; return result; } @@ -103,7 +107,7 @@ string HttpParser::generateMultipartBoundary(const vector<HttpReqArg>& args) { string result; srand((unsigned int) time(nullptr)); for (const HttpReqArg& item : args) { - if (item.isFile) { + if (item.isFile) { while (result.empty() || item.value.find(result) != item.value.npos) { result += StringTools::generateRandomString(4); } |