This is a migrated thread and some comments may be shown as answers.

C# Fiddler (oSession does not exist) error

2 Answers 174 Views
Fiddler Classic
This is a migrated thread and some comments may be shown as answers.
Dream
Top achievements
Rank 1
Iron
Dream asked on 22 Apr 2021, 10:21 AM

https://docs.telerik.com/fiddler/knowledge-base/fiddlerscript/modifyrequestorresponse?_ga=2.226810973.1912327690.1619085606-390831375.1615941114

 

I reviewed the content on this link. I added the nuget library. Why can't I use these codes? When using it with C #, I get an error as I mentioned in the appendix. "'oSession' does not exist in the current context" What is the cause of this error? I cannot use any code related to Fiddler. What causes the oSession error? I want to work on FiddlerCore, but I couldn't find a solution for this error.

2 Answers, 1 is accepted

Sort by
0
Rosen Vladimirov
Telerik team
answered on 27 Apr 2021, 04:31 AM

Hello,

You can use the session object in any of the session events, for example BeforeRequest and BeforeResponse as shown in FiddlerCore's documentation. Keep in mind your FiddlerCore trial is 30 days and after that you'll have to purchase a license in order to continue using the product.
The article you've found is not about FiddlerCore, it is about Fiddler Classic,  where you can use FiddlerScript to modify the request and response.

Regards,
Rosen Vladimirov
Progress Telerik

Love the Telerik and Kendo UI products and believe more people should try them? Invite a fellow developer to become a Progress customer and each of you can get a $50 Amazon gift voucher.

Dream
Top achievements
Rank 1
Iron
commented on 27 Apr 2021, 12:23 PM

Thanks, I know it will be bought. I'm trying to test and try something before buying. However, I could not do anything.

How can I change the response value of a URL in C #? There is no sample source code for this. I'm trying all those codes are working incorrectly. Is there a document that works properly?

I will be coding with C # in Visual studio platform. This requires a properly working example.
0
Rosen Vladimirov
Telerik team
answered on 29 Apr 2021, 01:18 PM

Hello,

In order to modify the reponse, you need to ensure the session is set to buffered mode. This should be done in some of the early events of the response, for example the ResponseHeadersAvailable, where you can grab the session object and set bBufferResponse property to true. If the property is not set to true, in the BeforeResponse event you'll receive a copy of the response, while it will be streamed to the client as well. So your modifications will not be applied to the response that the client will receive.

After that, you can handle the BeforeResponse event and modify the session's response as per your requirements.

To demonstrate how to achieve this, I've prepared a sample project, which you can find as an attachment. When you run it, it will ask you to trust the root certificate, please do so. After that, in the Console you'll see that the proxy is set. Now you can open https://yahoo.com in your browser and you shouldn't see the actual page, but a modified response. Now you can get back to the Console app and press Enter - this will remove the already set system proxy and exit the application.

Hope this helps.

Regards,
Rosen Vladimirov
Progress Telerik

Тhe web is about to get a bit better! 

The Progress Hack-For-Good Challenge has started. Learn how to enter and make the web a worthier place: https://progress-worthyweb.devpost.com.

Dream
Top achievements
Rank 1
commented on 11 Jun 2021, 01:22 AM | edited

For example, when I go to https://www.yahoo.com/fiddler_hello, I get a 404 error result. How can I change the response result even though this page has 404 errors?

So if a page gives 404 errors, the application does not change it. How can I get the response I want when I enter https://www.yahoo.com/fiddler_hello even though the page gives a 404 error?
Nick Iliev
Telerik team
commented on 11 Jun 2021, 08:16 AM

Hello,

 

You could use the BeforeResponse event to modify the status codes and headers. I've created this basic example to demonstrate how to change the status code from 404 to 200. You will notice that when capturing the test URL (HTTP://httpbin.org/statuscode/404) it will return status code 200 in the AfterSessionComplete event.

 

Dream
Top achievements
Rank 1
commented on 11 Jun 2021, 10:58 AM | edited

Oh god, really thank you <3

I have one last question. Thank you very much indeed.

For example, I want to redirect yahoo.com site to telerik.com. So when I go to yahoo.com, I want to be on telerik.com. Is it possible to do this too?
Nick Iliev
Telerik team
commented on 14 Jun 2021, 08:29 AM

Yes, virtually anything that can be achieved via modifying a request/response is doable via FiddlerCore. Use this SO thread as a reference on how to achieve it via FiddlerCore.
Tags
Fiddler Classic
Asked by
Dream
Top achievements
Rank 1
Iron
Answers by
Rosen Vladimirov
Telerik team
Share this question
or