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\"}
1 Action() 2 { 3 4 5 web_reg_save_param("msg", 6 "LB=message\":\"", 7 "RB=\"", 8 "Ord=1", 9 LAST);10 11 12 lr_start_transaction("post_json2");13 14 //json接口需要加header请求头15 web_add_header("Content-type", "application/json"); 16 17 web_custom_request("post_json", "Method=POST", 18 19 "URL=http://localhost:8080/pinter/com/register", 20 21 "Body={\"userName\":\"test\",\"password\":\"1234\",\"gender\":1,\"phoneNum\":\"110\",\"email\":\"beihe@163.com\",\"address\":\"beijing\"}", 22 23 "TargetFrame=", 24 25 LAST );26 27 // //由于message返回为乱码字符串无法判断?需要作编码转化。28 // 因为msg 是内部函数 需要转化为c语言的函数使用, LR_ENC_UTF8-->LR_ENC_SYSTEM_LOCALE 又变成了 lr的函数,因为是lr帮你存的29 30 lr_convert_string_encoding(lr_eval_string("{msg}") , LR_ENC_UTF8 , LR_ENC_SYSTEM_LOCALE , "sEncoding"); 31 32 //所以这一步还要转 ==0 不要 ==1 0表示字符相等33 if (strcmp(lr_eval_string("{sEncoding}") , "注册成功") == 0) {34 lr_end_transaction("post_json2", LR_PASS);35 36 }else{37 lr_end_transaction("post_json2", LR_FAIL);38 }39 40 41 return 0;42 }