FindInResponse to give next string element

0 Answers 189 Views
Fiddler Classic
Ararad
Top achievements
Rank 1
Ararad asked on 01 Jun 2022, 07:01 AM | edited on 01 Jun 2022, 07:18 AM

Hi,

I'm trying to find the way to read the next string after finding given text in response html.

It will contain fe. "someNum is: 1234" but the number will be different in every response.

My question is, how to grab the number, which sits in the string, when finding begginnig of the string which is "someNum is:"

 

if (oSession.oResponse.headers.ExistsAndContains("Content-Type", "html") {

    oSession.utilDecodeResponse();

oSession.utilFindInResponse("someNum is:");

var = <here I want to put the value, whatever it is>;

oSession.Log.LogString(var);

}

Thanks.

Nick Iliev
Telerik team
commented on 02 Jun 2022, 06:12 AM

It sounds like you need to implement a search for a specific string and then get n-characters after that string.  This is not Fiddler specific but more language-specific so you could look up the options that you have with C# for solving similar problems (look for threads like this one).
Ararad
Top achievements
Rank 1
commented on 01 Jul 2022, 11:38 AM

Well I tried but I cannot reach that string in fiddlerscript, I think it's fiddler specific as accessing the response code and withdrawing its html code requires some specific behavior.

I'm not sure how to access the string which I don't even read, I just FindInResponse string before the one I need to read. I think here is the clue.

Nick Iliev
Telerik team
commented on 03 Jul 2022, 10:59 AM

The method utilFindInResponse will return its index or -1 (if the search term is not found). You can use utilReplaceInRespone to replace part of the response

Ararad
Top achievements
Rank 1
commented on 06 Jul 2022, 07:38 AM

I didn't get, what would utilReplaceInResponse give me there.

utilFindInResponse finds a part of the string "someNum is:" other part, which dynamically change is a number f.e. "123", so when I found with utilFindInResponse beginning, what would give me its returned index? I'm lost here.

Full string: "someNum is: 123", found string: "someNum is:", unknown: "number"

Nick Iliev
Telerik team
commented on 06 Jul 2022, 08:42 AM

Ok, if you can use replace, then you still need to grab the whole response body, replace the part you are looking for, and then set the modified body.

 

oSession.utilDecodeResponse();
var oBody = System.Text.Encoding.UTF8.GetString(oSession.responseBodyBytes);

// Replace the string occurrence with the value you need e.g. while using ReGex or other techniques
var myRegex = <some-regex-action-here>
oBody = oBody.replace(myRegex, "");

// Set the response body
oSession.utilSetResponseBody(oBody); 

Ararad
Top achievements
Rank 1
commented on 15 Aug 2022, 04:54 PM

Thanks for your input, but I think you still missunderstand the issue here.

I don't want to replace anything, I just want to read the next string signs after "someNum is:" (which will be a number from 0-1000.

So I use here:

oSession.utilDecodeResponse();
oSession.utilFindInResponse("someNum is:");

Let's say the full string is "someNum is: 123", and when I already find the "someNum is:" string, I want to check this value after the found string. So I want to store 123 (which changes, I don't know the num which I will find) and then print it with:

 oSession.oFlags["ui-comments"] = foundNumber
where in our example case, foundNumber = "123". How to find this "123"?

No answers yet. Maybe you can help?

Tags
Fiddler Classic
Asked by
Ararad
Top achievements
Rank 1
Share this question
or