Skip to content

NetworkKMM Post请求不传body在鸿蒙平台上会导致请求变成Get #42

Description

@LiPengfei0106

好像是因为在curl_wrapper.cpp#L250-#L266中是通过postBody来判断是否为post请求的。是否应该给request增加一个method字段会更灵活

        // 根据post body长度是否大于0, 判断是否是post请求
        if (postBodyLen > 0 && postBody != nullptr) {
            logI(log_tag_, "curl post request, body len:" + std::to_string(postBodyLen) + ", body:" + postBody);
            // size of the POST input data
            curl_easy_setopt(curl_, CURLOPT_POSTFIELDSIZE, postBodyLen);
            curl_easy_setopt(curl_, CURLOPT_POST, 1L);
            if (postBodyLen >= 8 * 1024 * 1024) {
                logI(log_tag_, "Enter above 8MB branch.");
                // 传 body 指针,不会拷贝数据,因此必须确保 perform 之前数据有效
                curl_easy_setopt(curl_, CURLOPT_POSTFIELDS, postBody);
            } else {
                logI(log_tag_, "Enter libcurl below 8MB branch.");
                // 7.17.1 以上 libcurl 版本支持,最大不能超过 8MB 数据
                // 传 body 指针,会拷贝数据,因此必须先设置 body 大小,否则按空字符串处理
                curl_easy_setopt(curl_, CURLOPT_COPYPOSTFIELDS, postBody);
            }
        }

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions