Search code examples
c#xmlparametersfiddler

How do I get values from parameters?


This may be a simple answer but I am having difficulty. I am using fiddler to see if various servers can connect to the internet. I am able to test it if the URL and proxy are hard coded as seen below

 HttpWebRequest request = (HttpWebRequest)WebRequest.Create("http://www.stackoverflow.com");
   request.Method = "GET";
WebProxy myProxy = new WebProxy("http://localhost:9999");
   request.Proxy = myProxy;

I want to be able to test it using parms in an xml file. The parms look like this:

protected override void LoadParameters(IList<IRuleParameter> parms)
    {
        _url = (HttpWebRequest)WebRequest;
        _proxy = new WebProxy();
    }

The parms are typed into the xml file like this:

<Parm name="Url" value="http://google.com" />
<Parm name="Proxy" value="http://localhost:9999" /

How can I call them so that I can place values into xml rather than placing values in the solution itself? Thanks in advance


Solution

  • This answer is based on your comment about why reading into local variables doesn't work. Can you double check the types of _httpUrl and _httpProxy? It sounds like those variables are of type string when they need to be HttpWebRequest and WebProxy respectively.

    I think if you did;

       _httpUrl = paramVal;
    

    it would compile and run with no problems. That error is saying _httpUrl is a string but you're trying to assign and HttpWebRequest to it. The other option for fixing it is changing the type of _httpUrl

        // definition where ever that is
        HttpWebRequest _httpUrl;
    
    
        //no code change required in body of LoadParams
        //this line caused the compiler error but will be fine now
        _httpUrl = (HttpWebRequest)WebRequest.Create(paramVal);
    

    Remember to do give the same treatment to _httpProxy.