vb.netperformancevisual-studiowebtest

Extract Text from Response Body in Coded Webtest using vb


I have a Web performance Script in Visual Studio. I have turned this into Coded Webtest in VB by clicking on the Generate Code button.

In my web test there are a 5 functions. Apart from the 1st the others are for SQL Procedures.

Among a few things, I need a web request that does a certain action. Based on that action, In the response body - it generates a Unique Id.

I need this Id to make it accessible across all the functions.

The Response body is something like this :

0x00000000  7B  22  69  64  22  3A  36  35  33  30  36  36  33  7D            {"id":2133221}  

Now I wanted to know, how do I do it. I just need 2133221.

I tried using the Context Parameter name and appending it to a .to string...it did not work. I tried doing by looking over the net and trying out a few options. I'm lost now. Can anyone help.


Solution

  • The simplest solution is the below one.

    str = "0x00000000 7B 22 69 64 22 3A 36 35 33 30 36 36 33 7D {""id"":2133221}"
    
    arr = Split(str, ":")
    strID = Left(arr(1), len(arr(1)) - 1)
    
    msgbox strId
    

    However, If you still need a more robust one, try regex