improve the parsing of form data

This commit is contained in:
Chunting Gu
2020-12-07 14:16:08 +08:00
parent 63abc5bbda
commit abd30ab69d
6 changed files with 45 additions and 31 deletions
+14 -9
View File
@@ -11,14 +11,19 @@ namespace bfs = boost::filesystem;
int main(int argc, char* argv[]) {
if (argc < 2) {
std::cout << "usage: form_client <upload_dir> [url]" << std::endl;
std::cout << "Usage: form_client <upload_dir> [url]" << std::endl;
std::cout << std::endl;
std::cout << "default url: http://httpbin.org/post" << std::endl;
std::cout << "Default url: http://httpbin.org/post" << std::endl;
std::cout << std::endl;
std::cout << "examples:" << std::endl;
std::cout << " $ form_client E:/github/webcc/data/upload" << std::endl;
std::cout << " $ form_client E:/github/webcc/data/upload "
std::cout << "Examples:" << std::endl;
std::cout << "(Post to httpbin.org)" << std::endl;
std::cout << " $ ./form_client path/to/webcc/data/upload" << std::endl;
std::cout << " $ ./form_client path/to/webcc/data/upload "
<< "http://httpbin.org/post" << std::endl;
std::cout << "(Post the example 'form_server')" << std::endl;
std::cout << " $ ./form_client path/to/webcc/data/upload "
"http://localhost:8080/upload"
<< std::endl;
return 1;
}
@@ -41,10 +46,10 @@ int main(int argc, char* argv[]) {
webcc::ClientSession session;
try {
auto r = session.Send(webcc::RequestBuilder{}.Post(url).
FormFile("file", upload_dir / "remember.txt").
FormData("json", "{}", "application/json")
());
auto r = session.Send(webcc::RequestBuilder{}
.Post(url)
.FormFile("file", upload_dir / "remember.txt")
.FormData("json", "{}", "application/json")());
std::cout << r->status() << std::endl;