我有一个像这样如何“使用”使用与“出”参数
private bool VerbMethod(string httpVerb, string methodName, string url, string command, string guid, out HttpWebResponse response)
的方法我用这个像这样
HttpWebResponse response;
if (VerbMethod("POST", "TheMethod", "http://theurl.com", "parameter1=a", theGuid, out response))
{
using (StreamReader sr = new StreamReader(response.GetResponseStream()))
{
string responseString = sr.ReadToEnd();
}
它返回一个布尔值,指定如果方法进展顺利,并将响应设置为out参数以获取数据。
我有时会得到超时,然后后续请求也超时。我看到了这个SO WebRequest.GetResponse locks up?
它推荐了using
关键字。问题是,用上面的方法签名,我不知道该怎么做。
- 我应该在最后手动调用dispose吗?
- 有没有办法仍然使用
using
与out
参数? - 重写该方法,所以它不公开
HttpWebResponse
?