HttpHeaders.TryAddWithoutValidation是否验证? [英] Does HttpHeaders.TryAddWithoutValidation validate or not?

查看:489
本文介绍了HttpHeaders.TryAddWithoutValidation是否验证?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对该功能的名称有些困惑。
为什么不只是 TryAdd ?无法验证的是什么?如果我使用此功能,在某些情况下它还能抛出吗?我可以以某种方式尝试添加而不会遇到任何异常,并且如果失败则返回false吗?

I'm a bit confused by the name of this function. Why isn't it just TryAdd? What is it that it doesn't validate? If I use this function, can it still throw in some cases? Can I somehow "try to add" without getting any exceptions and only false returned if it fails?

编辑:
我认为这两个问题相互对立。如果我使用 TryAddWithoutValidation 进行调用,它是否实际上添加了无效的标头,或者如果它们无效则仅返回false?

I think the 2 questions are opposing each other. If I call with TryAddWithoutValidation does it actually add the invalid headers or it just returns false if they are invalid?

推荐答案

HttpHeaders.TryAddWithoutValidation 如果键为空/空或在无效的标头

The HttpHeaders.TryAddWithoutValidation returns false if the key is null/empty OR it's in the list of invalid headers.

添加方法,除了引发异常而不返回false之外,还调用方法 ParseAndAddValue 。在内部,它为您尝试添加的每个键获取一个解析器,并且仅在解析成功后才接受值(例如,检查要添加的键是否对这种请求有效)。

The Add method, besides throwing exceptions instead of returning false, calls the method ParseAndAddValue. Internally it gets a parser for each key you try to add and only accepts the value if the parse is successfull (checking if the key you're trying to add is valid for that kind of request, for example).

这篇关于HttpHeaders.TryAddWithoutValidation是否验证?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆