当前位置: 首页>>代码示例>>C++>>正文


C++ Holder::getPost方法代码示例

本文整理汇总了C++中Holder::getPost方法的典型用法代码示例。如果您正苦于以下问题:C++ Holder::getPost方法的具体用法?C++ Holder::getPost怎么用?C++ Holder::getPost使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Holder的用法示例。


在下文中一共展示了Holder::getPost方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: curl_easy_setopt

JNIEXPORT jint JNICALL Java_com_netbirdtech_libcurl_Curl_setFormdataNative
  (JNIEnv* env, jobject obj, jlong handle, jobjectArray multi_array) {
    Holder* holder = (Holder*) handle;
    if (holder == NULL) {
        return 0;
    }
    CURL* curl = holder->getCurl();

    struct curl_httppost* post = holder->getPost();;
    struct curl_httppost* last = NULL;
    // clear all
    if (post != NULL) {
        //LOGD("clear previous form.");
        curl_formfree(post);
        post = NULL;
    }

    if (multi_array != NULL) {
        CURLFORMcode code;
        int len = env->GetArrayLength(multi_array);
        //LOGD("set name/parts size=%d", len);
        for (int i = 0; i < len; i++) {
            //LOGV(".");
            jobject part = env->GetObjectArrayElement(multi_array, i);
            jstring name = (jstring) env->CallObjectMethod(part, MID_MultiPart_get_name);
            jstring filename = (jstring) env->CallObjectMethod(part, MID_MultiPart_get_filename);
            jstring content_type = (jstring) env->CallObjectMethod(part, MID_MultiPart_get_content_type);
            jbyteArray content = (jbyteArray) env->CallObjectMethod(part, MID_MultiPart_get_content);
            jbyte* bytes = env->GetByteArrayElements(content, 0);
            int content_length = env->GetArrayLength(content);

            holder->addByteArrayGlobalRefs(env->NewGlobalRef(content), (const char*)bytes); // release after perform

            const char* name_str = env->GetStringUTFChars(name, 0);

            // content_type and filename may be null
            if (content_type == NULL && filename == NULL) {
            	code = curl_formadd(&post, &last,
            						CURLFORM_COPYNAME, name_str,
            						CURLFORM_BUFFER, "file.dat",
            						CURLFORM_BUFFERPTR, bytes,
            						CURLFORM_BUFFERLENGTH, content_length,
								    CURLFORM_END);
            } else if (content_type == NULL) {
            	const char* filename_str = env->GetStringUTFChars(filename, 0);
            	code = curl_formadd(&post, &last,
									CURLFORM_COPYNAME, name_str,
									CURLFORM_BUFFER, filename_str,
									CURLFORM_BUFFERPTR, bytes,
									CURLFORM_BUFFERLENGTH, content_length,
									CURLFORM_END);
            	env->ReleaseStringUTFChars(filename, filename_str);
            } else if (filename == NULL) {
            	const char* content_type_str = env->GetStringUTFChars(content_type, 0);
            	code = curl_formadd(&post, &last,
									CURLFORM_COPYNAME, name_str,
									CURLFORM_BUFFER, "file.dat",
									CURLFORM_CONTENTTYPE, content_type_str,
									CURLFORM_BUFFERPTR, bytes,
									CURLFORM_BUFFERLENGTH, content_length,
									CURLFORM_END);
				env->ReleaseStringUTFChars(content_type, content_type_str);
            } else {
            	const char* filename_str = env->GetStringUTFChars(filename, 0);
            	const char* content_type_str = env->GetStringUTFChars(content_type, 0);
            	code = curl_formadd(&post, &last,
									CURLFORM_COPYNAME, name_str,
									CURLFORM_BUFFER, filename_str,
									CURLFORM_CONTENTTYPE, content_type_str,
									CURLFORM_BUFFERPTR, bytes,
									CURLFORM_BUFFERLENGTH, content_length,
									CURLFORM_END);
            	env->ReleaseStringUTFChars(filename, filename_str);
            	env->ReleaseStringUTFChars(content_type, content_type_str);
            }

            env->ReleaseStringUTFChars(name, name_str);
        }

        if (code != CURL_FORMADD_OK) {
        	////LOGW("curl_formadd error %d", code);
        	curl_formfree(post);
        	// TODO return fromadd error or setopt error?
        	return (int) code;
        }
    }

    if (post != NULL) {
    	//LOGV("set_opt CURLOPT_HTTPPOST");
		holder->setPost(post);
		return curl_easy_setopt(curl, CURLOPT_HTTPPOST, post);
    }
    return 0;
}
开发者ID:mahongquan,项目名称:java-jni,代码行数:94,代码来源:Main.cpp


注:本文中的Holder::getPost方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。