2

我需要从我的代码中删除 EnsureSuccessStatusCode() 方法并手动抛出 HttpRequestException。查看 EnsureSuccessStatusCode 的内部结构:

public HttpResponseMessage EnsureSuccessStatusCode()
    {
      if (!this.IsSuccessStatusCode)
      {
        if (this.content != null)
          this.content.Dispose();
        throw new HttpRequestException(string.Format((IFormatProvider) CultureInfo.InvariantCulture, SR.net_http_message_not_success_statuscode, new object[2]
        {
          (object) this.statusCode,
          (object) this.ReasonPhrase
        }));
      }
      return this;
    }

在这种情况下,如何替换“SR.net_http_message_not_success_statuscode”?因为它是一个内部属性,我不能在我的代码中使用它。我想要这样的东西:

throw new HttpRequestException(string.Format(CultureInfo.InvariantCulture, "StatusCode: {0}, ReasonPhrase: {1}", new object[]
                        {
                            response.StatusCode,
                            response.ReasonPhrase
                        }));

是正确的替换吗?

4

0 回答 0