我有一个HttpWebResponse,并且StreamReader resharper指示我的httpResponse.GetResponseStream()可能为null,但是我不确定正确的语法。
using(var httpResponse = (HttpWebResponse)request.GetResponse())
{
if (httpResponse.StatusCode == HttpStatusCode.OK)
{
//This line is where Resharper Is complaining
using (var streamReader = new StreamReader(httpResponse.GetResponseStream()))
{
var result = streamReader.ReadToEnd();
...
}
}
else
{...
答案 0 :(得分:2)
只需检查["cat"]
不返回空值即可:
httpResponse.GetResponseStream()