257,flutterrun第三方路径

curl_easy_setopt(curl, CURLOPT_URL, “http://101.200.190.150:7777/login”);

//2 开启post请求开关

curl_easy_setopt(curl, CURLOPT_POST, true);

//3 添加post数据

curl_easy_setopt(curl, CURLOPT_POSTFIELDS, post_str);

//4 设定一个处理服务器响应的回调函数,deal_response是回调函数

curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, deal_response);

//5 给回调函数传递一个形参

curl_easy_setopt(curl, CURLOPT_WRITEDATA, &responseData);

//6 向服务器发送请求,等待服务器的响应

res = curl_easy_perform(curl);

if (res != CURLE_OK) {

__android_log_print(ANDROID_LOG_ERROR,TAG,“JNI-login:perform ERROR, rescode= [%d]\n”,

res);

return JNI_FALSE;

}

//(3) 等待服务器的响应 此刻的responseData就是从服务器获取的数据

/*

//成功

{

result: “ok”,

}

//失败

{

result: “error”,

reason: “why…”

}

  • */

//(4) 解析服务器返回的json字符串

root = cJSON_Parse(responseData.data);

cJSON *result = cJSON_GetObjectItem(root, “result”);

if(result && strcmp(result->valuestring, “ok”) == 0) {

//登陆成功

__android_log_print(ANDROID_LOG_ERROR,TAG,“JNI-login:login succ!!!”);

return JNI_TRUE;

}

else {

//登陆失败

cJSON* reason = cJSON_GetObjectItem(root, “reason”);

if (reason) {

//已知错误

__android_log_print(ANDROID_LOG_ERROR,TAG,“JNI-login:login error, reason = %s!!!”, reason->valuestring);

}

else {

//未知的错误

__android_log_print(ANDROID_LOG_ERROR,TAG,“JNI-login:login error, reason = Unknow!!!”);

}

return JNI_FALSE;

}

return JNI_TRUE;

}

服务器代码如下http_server.c:

#include <stdio.h>

#include <stdlib.h>

#include <unistd.h> //for getopt, fork

#include <string.h> //for strcat

//for struct evkeyvalq

#include <sys/queue.h>

#include <event.h>

//for http

//#include <evhttp.h>

#include <event2/

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值