我有一個像這樣如何「使用」使用與「出」參數
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
?