[英]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. 我希望能够使用xml文件中的parms对其进行测试。 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: 可以将parms键入到xml文件中,如下所示:
<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? 如何调用它们,以便可以将值放入xml中而不是将值放在解决方案本身中? Thanks in advance
提前致谢
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
? 您可以仔细检查
_httpUrl
和_httpProxy
的类型吗? It sounds like those variables are of type string
when they need to be HttpWebRequest
and WebProxy
respectively. 听起来这些变量在分别需要分别为
HttpWebRequest
和WebProxy
为string
类型。
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. 该错误
_httpUrl
是一个string
但您正在尝试为其分配HttpWebRequest
。 The other option for fixing it is changing the type of _httpUrl
解决该问题的另一种方法是更改
_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
. 记住要对
_httpProxy
进行相同的处理。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.