Highlighted
Valued Contributor.
Valued Contributor.
3891 views

Need help on capture JSON response from server

Jump to solution

Hi all,

I am now writting script for Worklight server test and have some trouble.

Here is webservice's response

/*-secure-
{"challenges":{"wl_antiXSRFRealm":{"WL-Instance-Id":"kfi30hpd23m5r397ll0qulvsok"}}}*/

And I need extracly value of WL-INstance-ID .

Here are my code when I submit to webserver

web_add_header("x-wl-app-version","1.0");
web_add_header("x-wl-platform-version","7.1.0.0");

web_submit_data("init", 

        "Action=http://XXX/PruFastUAT/apps/services/api/PruFast/desktopbrowser/init", 
        "Method=POST", 
        "RecContentType=application/json", 
        "Referer=http://XXX/PruFastUAT/apps/services/www/PruFast/desktopbrowser/default/browser.html", 
        "Snapshot=t33.inf", 
        "Mode=HTML", 
        ITEMDATA, 
        "Name=isAjaxRequest", "Value=true", ENDITEM, 
        "Name=x", "Value=0.8243676177830881", ENDITEM, 
        LAST);

And Please refer to response from HTTPRequester. 

Thanks for your help

0 Likes
1 Solution

Accepted Solutions
Highlighted
Frequent Contributor.
Frequent Contributor.

Why aren't you using boundary based extraction? Try below.

web_reg_save_param_ex(
    "ParamName=param", 
    "LB=WL-Instance-Id\":\"", // left boundary
    "RB=\"", // right boundary
    "Ordinal=1",
    SEARCH_FILTERS,
    "Scope=Body", //where you need to search
LAST);

OR

web_reg_save_param_regex(
    "ParamName=param",
    "RegExp=\"WL-Instance-Id\":\"([^\"]*?)\"}", // regex expression
    SEARCH_FILTERS,
    LAST);


OR if it is a pure JSON response, you can also use a function called ' web_reg_save_param_json '.

Hope it helps.

View solution in original post

Tags (1)
4 Replies
Highlighted
Frequent Contributor.
Frequent Contributor.

Why aren't you using boundary based extraction? Try below.

web_reg_save_param_ex(
    "ParamName=param", 
    "LB=WL-Instance-Id\":\"", // left boundary
    "RB=\"", // right boundary
    "Ordinal=1",
    SEARCH_FILTERS,
    "Scope=Body", //where you need to search
LAST);

OR

web_reg_save_param_regex(
    "ParamName=param",
    "RegExp=\"WL-Instance-Id\":\"([^\"]*?)\"}", // regex expression
    SEARCH_FILTERS,
    LAST);


OR if it is a pure JSON response, you can also use a function called ' web_reg_save_param_json '.

Hope it helps.

View solution in original post

Tags (1)
Highlighted
Valued Contributor.
Valued Contributor.

I have tried but it returned an error:

 

    Action.c(66): Continuing after Error -26377: No match found for the requested parameter "param". Either the specified boundaries were not found in the response or the matched text is longer than current max html parameter size of 256 bytes. The total length of the response is 0 bytes. You can use "web_set_max_html_param_len" to increase the max parameter size.   [MsgId: MERR-26377]

0 Likes
Highlighted
Frequent Contributor.
Frequent Contributor.

which function did you try?

0 Likes
Highlighted
Valued Contributor.
Valued Contributor.

I have tried 

web_reg_save_param_ex


but I found the reason, I have put web_reg_save_ex before the web_submit_date and it worked like a horse ! 

Thanks very much for your help

The opinions expressed above are the personal opinions of the authors, not of Micro Focus. By using this site, you accept the Terms of Use and Rules of Participation. Certain versions of content ("Material") accessible here may contain branding from Hewlett-Packard Company (now HP Inc.) and Hewlett Packard Enterprise Company. As of September 1, 2017, the Material is now offered by Micro Focus, a separately owned and operated company. Any reference to the HP and Hewlett Packard Enterprise/HPE marks is historical in nature, and the HP and Hewlett Packard Enterprise/HPE marks are the property of their respective owners.