参数为json格式的接口

1.参数为json格式,需要添加一个header信息
web_add_header("Content-type", "application/json");

2.Json参数直接放在web_custom_request函数的body中,需要注意的是,json中的引号必须先进行转义,如以下格式:

{\"userId\":\"12346\",\"skuId\":\"110\",\"num\":\"3\",\"addressId\":\"123\",\"shipType\":\"3\",\"payType\":\"2\"}

 Action()
{ web_reg_save_param("msg",
"LB=message\":\"",
"RB=\"",
"Ord=1",
LAST); lr_start_transaction("post_json2"); //json接口需要加header请求头
web_add_header("Content-type", "application/json"); web_custom_request("post_json", "Method=POST", "URL=http://localhost:8080/pinter/com/register", "Body={\"userName\":\"test\",\"password\":\"1234\",\"gender\":1,\"phoneNum\":\"110\",\"email\":\"beihe@163.com\",\"address\":\"beijing\"}", "TargetFrame=", LAST ); // //由于message返回为乱码字符串无法判断?需要作编码转化。
// 因为msg 是内部函数 需要转化为c语言的函数使用, LR_ENC_UTF8-->LR_ENC_SYSTEM_LOCALE 又变成了 lr的函数,因为是lr帮你存的 lr_convert_string_encoding(lr_eval_string("{msg}") , LR_ENC_UTF8 , LR_ENC_SYSTEM_LOCALE , "sEncoding"); //所以这一步还要转 ==0 不要 ==1 0表示字符相等
if (strcmp(lr_eval_string("{sEncoding}") , "注册成功") == ) {
lr_end_transaction("post_json2", LR_PASS); }else{
lr_end_transaction("post_json2", LR_FAIL);
} return ;
}
上一篇:Ubuntu16.04下编译安装OpenCV3.4.0(C++ & python)


下一篇:codeblocks 设置代码自动补全