| 332 | } |
| 333 | |
| 334 | static int processPostFileTask(CAHttpRequest *request, write_callback callback, void *stream, int32_t *responseCode, write_callback headerCallback, void *headerStream) |
| 335 | { |
| 336 | CURLRaii curl; |
| 337 | bool ok = curl.init(request, callback, stream, headerCallback, headerStream); |
| 338 | if (!ok) |
| 339 | return 1; |
| 340 | |
| 341 | curl_httppost* pFormPost = NULL; |
| 342 | curl_httppost* pLastElem = NULL; |
| 343 | |
| 344 | curl_formadd(&pFormPost, &pLastElem, CURLFORM_COPYNAME, "filepath", CURLFORM_FILE, |
| 345 | request->getFileNameToPost(), CURLFORM_CONTENTTYPE, "application/octet-stream", CURLFORM_END); |
| 346 | |
| 347 | int requestDataSize = request->getRequestDataSize(); |
| 348 | if (requestDataSize>0) |
| 349 | { |
| 350 | std::string strReq = request->getRequestData(); |
| 351 | strReq.resize(request->getRequestDataSize()); |
| 352 | std::vector<std::string> vv = CrossApp::Parse2StrVector(strReq, "&"); |
| 353 | for (int i = 0; i < vv.size(); i++) |
| 354 | { |
| 355 | std::vector<std::string> v = CrossApp::Parse2StrVector(vv[i], "=", true); |
| 356 | if (v.size() == 2) |
| 357 | { |
| 358 | curl_formadd(&pFormPost, &pLastElem, CURLFORM_COPYNAME, v[0].c_str(), CURLFORM_COPYCONTENTS, v[1].c_str(), CURLFORM_END); |
| 359 | } |
| 360 | } |
| 361 | curl_formadd(&pFormPost, &pLastElem, CURLFORM_COPYNAME, "act", CURLFORM_COPYCONTENTS, "end", CURLFORM_END); |
| 362 | } |
| 363 | |
| 364 | ok = curl.setOption(CURLOPT_HTTPPOST, pFormPost) |
| 365 | && curl.perform(responseCode); |
| 366 | |
| 367 | if (pFormPost) |
| 368 | { |
| 369 | curl_formfree(pFormPost); |
| 370 | pFormPost = NULL; |
| 371 | } |
| 372 | return ok ? 0 : 1; |
| 373 | } |
| 374 | |
| 375 | |
| 376 | CAHttpClient* CAHttpClient::getInstance(int thread) |