[英]System.FormatException: Input string was not in a correct format. c#
[英]System.FormatException: Invalid format. While trying to add a Header Key
我有一个调用 API 的函数,用于向响应标头添加密钥授权。
即: _httpClient.DefaultRequestHeaders.Add("Authorization", accessToken);
但是我有一个函数,我将在其中反复调用相同的函数,直到根据预定义的页面大小获得所有结果。
在这里,当第一次调用该函数时,上面的函数工作正常,但是随后对同一函数的递归调用,抛出错误System.FormatException: Invalid format。
堆栈跟踪 :
System.FormatException: Invalid format.
at System.Net.Http.Headers.HttpHeaders.AddInternal (System.String name, IEnumerable`1 values, System.Net.Http.Headers.HeaderInfo headerInfo, Boolean ignoreInvalid) [0x00000] in <filename unknown>:0
at System.Net.Http.Headers.HttpHeaders.Add (System.String name, IEnumerable`1 values) [0x00000] in <filename unknown>:0
at System.Net.Http.Headers.HttpHeaders.Add (System.String name, System.String value) [0x00000] in <filename unknown>:0
at (System.String verb, System.String url, System.String parameters) [0x00041] in
defaultheaderrequest 已经在之前的请求中添加了相同的 Key。
因此,我需要这些键来清除它,然后再次使用,
_httpClient.DefaultRequestHeaders.Clear();
浪费异常消息是什么。 难道没有更合适的异常消息吗?
完全浪费了开发人员的时间。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.