Troy Hunt
Troy Hunt

Reputation: 20387

FiddlerScript throws NullReferenceException on headers.ExistsAndContains

This is driving me nuts and it may be something simple, but every time I call the following from Fiddler script is throws a NullReferenceException:

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

This is straight off the Fiddler script knowledge base and I've got the same thing happening on two different Win 8 machines. It seems that oSession.oResponse.headers is null and yes, I am calling this from within OnBeforeRequest!

Same deal with oSession.responseBodyBytes - it looks like the response is null inside OnBeforeRequest. Otherwise Fiddler is behaving normally, traffic proxies through just fine and everything else looks good.

Ideas?

Upvotes: 0

Views: 527

Answers (1)

EricLaw
EricLaw

Reputation: 57075

The oResponse.headers and oSession.responseBodyBytes objects don't exist until after the request has been sent to the server and the response has been read back. If you want to interact with the Response headers and body, do so inside the OnBeforeResponse function instead.

The KB was mangled a bit when updated for the new site. I'll file a bug to have this made more explicit.

Upvotes: 2

Related Questions