20191013
#include <stdio.h>
#include <stdlib.h>
#include <curl/curl.h>
#define POSTDATA "{\"username\":\"ace",\"passwd\":\"123123\",\"type\":\"10\"}"
//长度 ptr 收到服务器返回数据首地址 size 返回每个数据的大小
// 回调函数
size_t write_callback(char *ptr,size_t size, size_t nmemb, void *userdata){
FLIE *fp = (FILE*)userdata;
int count = size*nmemb;
int fwrite_len = 0;
fwrite_len = fwrite(ptr,size,nmemb,fd);
printf("读取数据的长度%d",count);
#include <stdlib.h>
#include <curl/curl.h>
#define POSTDATA "{\"username\":\"ace",\"passwd\":\"123123\",\"type\":\"10\"}"
//长度 ptr 收到服务器返回数据首地址 size 返回每个数据的大小
// 回调函数
size_t write_callback(char *ptr,size_t size, size_t nmemb, void *userdata){
FLIE *fp = (FILE*)userdata;
int count = size*nmemb;
int fwrite_len = 0;
fwrite_len = fwrite(ptr,size,nmemb,fd);
printf("读取数据的长度%d",count);
}
int main(void)
{
FILE *fp = NULL;
CURL *curl = NULL;
CURLcode res;
curl = curl_easy_init();
if(curl == NULL)
{
return -1;
}
//文件
fp = fopen("file,txt","w");
//设定服务器
curl_easy_setopt(curl,CURLOPT_URL,"http://101.200.190.150:7777/");
//
curl_easy_setopt(curl,CURLOPT_PSOT,1);
curl_easy_setopt(curl,CURLOPT_PSOTFIELDS,POSTDATA);
res = curl_easy_perform(curl);
if(res != CURL_OK)
{
printf("perform error res = %d",res);
return -1;
}
curl_easy_cleanup(curl);
fclose(fp);
return 0;
}
int main(void)
{
FILE *fp = NULL;
CURL *curl = NULL;
CURLcode res;
curl = curl_easy_init();
if(curl == NULL)
{
return -1;
}
//文件
fp = fopen("file,txt","w");
//设定服务器
curl_easy_setopt(curl,CURLOPT_URL,"http://101.200.190.150:7777/");
//
curl_easy_setopt(curl,CURLOPT_PSOT,1);
curl_easy_setopt(curl,CURLOPT_PSOTFIELDS,POSTDATA);
res = curl_easy_perform(curl);
if(res != CURL_OK)
{
printf("perform error res = %d",res);
return -1;
}
curl_easy_cleanup(curl);
fclose(fp);
return 0;
}
unname -a 查看系统版本
linux
1 把libcurl头文件添加JNI文件中
把编译后生成的平台库libcurl.a 复制到JNI文件夹中
将libcurl.a 添加到android中
2 再Android.mk 中加入
include $(CLEAR_VARS)
#libcurl.a
LOCA_MODULE := libcurl
LOCAL_SRC_FILES := libcurl.a
include #(PREBUILT_STATIC_LIBRARY)
include $(CLEAR_VARS)
#libcurl.a
LOCA_MODULE := libcurl
LOCAL_SRC_FILES := libcurl.a
include #(PREBUILT_STATIC_LIBRARY)
3 在app/build.gradle文件中
defaultConfig{
ndk{ //生成中android中依赖的库
moduleName "testjni"
ldLibs "log","z" 依赖的库
adiFilters "armeabi" 平台版本
}
}
ldLibs "log","z" 依赖的库
adiFilters "armeabi" 平台版本
}
}
4 //指定编译编译的平台 添加Application.mk
ndk-build.cmd APP_ABI="armeabi"
5 在login.cpp中添加
#include <curl/curl.h>
在login的jni接口中使用curl_easy_init();
#include <curl/curl.h>
在login的jni接口中使用curl_easy_init();