Web_custom_request- Vugen中的JSON数据

时间:2017-07-31 05:27:47

标签: json loadrunner

LR脚本抛出警告并且JSON响应失败。

以下是脚本

char * request_json_base;

char * request_json;

web_add_header(" Content-Type"," application / json; charset = utf-8");

request_json_base=  "{\"GLDefaultId\":0,\"ProjectId\":{ContactProjectId},\"CoaMainId\":10,\"UserId\":{UserId},\"Notes\":\"\",\"PRO_GLDefaultValue\":[{\"GLDefaultValueId\":0,\"GLDefaultId\":0,\"SegmentId\":16,\"Alias\":\"ACT\",\"SegmentType\":\"DETAIL\",\"FunctionTypeId\":0,\"Value\":\"&&&\",\"Mask\":\"&&&\",\"IsRequired\":true,\"LastModified\":null,\"IsCoaRequired\":true},{\"GLDefaultValueId\":0,\"GLDefaultId\":0,\"SegmentId\":17,\"Alias\":\"ST\",\"SegmentType\":\"SET\",\"FunctionTypeId\":0,\"Value\":\"&&\",\"Mask\":\"&&\",\"IsRequired\":false,\"LastModified\":null,\"IsCoaRequired\":false}]}",

request_json = lr_eval_string(request_json_base);

lr_save_string(request_json," REQUEST_JSON_PARAM");

web_custom_request("PRO_GLDefault",
    "URL=https://{URL}/PayrollWebApi/V1/PRO_GLDefault?userId={UserId}",
    "Method=POST",
    "TargetFrame=",
    "Resource=0",
    "RecContentType=application/json",
    "Referer=",
    "Snapshot=t299.inf",
    "Mode=HTML",
    "EncType=application/json",
    "Body={REQUEST_JSON_PARAM}",
LAST); 

以下是重播日志:

Action3_SUNP_ProjectSetup_RatesandSetupInfo.c(81):警告:字符串'" GLDefaultValueId":0," GLDefaultId":0," SegmentId":16 "别名":" ACT"" SegmentType":" DETAIL"" FunctionTypeId":0,&# 34;值":"&安培;&安培;&安培;""面膜":"&安培;&安培;&安培;"" IsRequired":真,"上次更改时间":空," IsCoaRequired":真'带参数分隔符的 不是参数。

Action3_SUNP_ProjectSetup_RatesandSetupInfo.c(81):警告:字符串'" GLDefaultValueId":0," GLDefaultId":0," SegmentId":17 "别名":" ST"" SegmentType":" SET"" FunctionTypeId":0,&# 34;值":"&安培;&安培;""面膜":"&安培;&安培;"" IsRequired" :假,"上次更改时间":空," IsCoaRequired":假'带参数分隔符的 不是参数。

Action3_SUNP_ProjectSetup_RatesandSetupInfo.c(83):通知:保存参数" REQUEST_JSON_PARAM = {" GLDefaultId":0," ProjectId":1810," CoaMainId&#34 ;:10,"用户ID":67,"注释":""" PRO_GLDefaultValue":[{" GLDefaultValueId&# 34;:0," GLDefaultId":0," SegmentId":16,"别名":" ACT"" SegmentType& #34;:" DETAIL"" FunctionTypeId":0,"值":"&安培;&安培;&安培;"&# 34;面膜":"&安培;&安培;&安培;"" IsRequired":真,"上次更改时间":空," IsCoaRequired&# 34;:真},{" GLDefaultValueId":0," GLDefaultId":0," SegmentId":17,"别名":& #34; ST"" SegmentType":" SET"" FunctionTypeId":0,"值":" &安培;&安培;""面膜":"&安培;&安培;"" IsRequired":假,"上次更改时间" :空," IsCoaRequired":假}]}"

Action3_SUNP_ProjectSetup_RatesandSetupInfo.c(85):{" $ id":" 1","消息":"发生错误"}

以下是原始请求电话:

"机体= {\" GLDefaultId \":0,\"专案编号\" {ContactProjectId},\" CoaMainId \&#34 ;:10,\"用户ID \" {用户ID},\"注\":\" \" \" PRO_GLDefaultValue \ ":[{\" GLDefaultValueId \":0,\" GLDefaultId \":0,\" SegmentId \":16,\ "别名\":\" ACT \" \" SegmentType \":\" DETAIL \" \&# 34; FunctionTypeId \":0,\"值\":\"&安培;&安培;&安培; \" \"面膜\&#34 ;:\"&安培;&安培;&安培; \" \" IsRequired \":真,\"上次更改时间\":空,\&# 34; IsCoaRequired \":真},{\" GLDefaultValueId \":0,\" GLDefaultId \":0,\" SegmentId \&# 34;:17,\"别名\":\" ST \" \" SegmentType \":\" SET \&# 34; \" FunctionTypeId \":0,\"值\":\"&安培;&安培; \" \"面具\":\"&安培;&安培; \" \" IsRequired \":假,\"上次更改时间\":空,\ " IsCoaRequired \":假}]}&#34 ;,         持续);

以下是录制过程中的成功回复:

请求 : {     " GLDefaultId":0,     " ProjectId":1806,     " CoaMainId":10,     " UserId":2,     "笔记":"",     " PRO_GLDefaultValue":[             {                 " GLDefaultValueId":0,                 " GLDefaultId":0,                 " SegmentId":16,                 " Alias":" ACT",                 " SegmentType":" DETAIL",                 " FunctionTypeId":0,                 "价值":"&&&",                 "面具":"&&&",                 " IsRequired":是的,                 " LastModified":null,                 " IsCoaRequired":是的             },             {                 " GLDefaultValueId":0,                 " GLDefaultId":0,                 " SegmentId":17,                 " Alias":" ST",                 " SegmentType":" SET",                 " FunctionTypeId":0,                 "价值":"&&",                 "面具":"&&",                 " IsRequired":false,                 " LastModified":null,                 " IsCoaRequired":false             }         ] }

响应: {     " $ id":" 1",     " GLDefaultId":1,     " ProjectId":1806,     " CoaMainId":10,     "笔记":"",     " PRO_GLDefaultValue":[             {                 " $ id":" 2",                 " GLDefaultValueId":1,                 " GLDefaultId":1,                 " Alias":" ACT",                 " FunctionTypeId":0,                 "价值":"&&&",                 " SegmentId":16,                 " IsRequired":是的,                 " ModifiedOn":" 7/1/2017 4:48:06 PM",                 " ModifiedBy":2,                 " PRO_GLDefault":{                         " $ ref":" 1"                     },                 " LastModified":null             },             {                 " $ id":" 3",                 " GLDefaultValueId":2,                 " GLDefaultId":1,                 " Alias":" ST",                 " FunctionTypeId":0,                 "价值":"&&",                 " SegmentId":17,                 " IsRequired":false,                 " ModifiedOn":" 7/1/2017 4:48:06 PM",                 " ModifiedBy":2,                 " PRO_GLDefault":{                         " $ ref":" 1"                     },                 " LastModified":null             }         ] }

请告诉我如何克服这个

谢谢, 拉吉

2 个答案:

答案 0 :(得分:0)

警告就是这样,一个警告,而不是一个错误,如果你的帖子中有花括号,那就预料到

第85行是什么产生错误的?

答案 1 :(得分:0)

请参阅以下两行:

request_json_base=  "{\"GLDefaultId\":0,\"ProjectId\":{ContactProjectId},\"CoaMainId\":10,\"UserId\":{UserId},\"Notes\":\"\",\"PRO_GLDefaultValue\":[{\"GLDefaultValueId\":0,\"GLDefaultId\":0,\"SegmentId\":16,\"Alias\":\"ACT\",\"SegmentType\":\"DETAIL\",\"FunctionTypeId\":0,\"Value\":\"&&&\",\"Mask\":\"&&&\",\"IsRequired\":true,\"LastModified\":null,\"IsCoaRequired\":true},{\"GLDefaultValueId\":0,\"GLDefaultId\":0,\"SegmentId\":17,\"Alias\":\"ST\",\"SegmentType\":\"SET\",\"FunctionTypeId\":0,\"Value\":\"&&\",\"Mask\":\"&&\",\"IsRequired\":false,\"LastModified\":null,\"IsCoaRequired\":false}]}",

request_json = lr_eval_string(request_json_base);

他们没有做你认为他们正在做的事情。您既没有为此数据分配空间(请参阅malloc()与char *变量的组合),也没有为C语言正确地为变量赋值(请参阅strcpy())

Stackoverflow上的另一个参考

How to correctly assign a new string value?