Invalid Uri:Uri 方案无效
我正在尝试通过 HttpWebRequest 建立连接。我正在从文本文件读取 url 链接。 但是,我收到“System.UriFormatException”错误。
我尝试在文本文件中的 url 链接前面添加 http:// 。但结果是一样的。
有什么解决办法吗?
I am trying to make a connection via HttpWebRequest. I am reading url links from a text file.
However, I am getting 'System.UriFormatException' error.
I have tried to add http:// in front of the url links in my text file. But the result is the same.
What can be the solution?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

如果错误仅在从文件读取值时发生,而不是在直接分配给
string
变量时发生,那么我猜测读取了额外的字符(引号、转义字符、回车符)返回/换行等)。尝试将第一个值读入
字符串
,然后将其与您期望的显式字符串
值进行比较。之后任何差异都应该是显而易见的。If the error only occurs when reading the values from a file, but not when assigned directly to a
string
variable, then I'm guessing that there are extra characters being read (quotes, escaped characters, carriage-return/line feeds, etc).Try reading the first value into a
string
, and then comparing that to what you expect in the explicitstring
value. Any differences should be obvious after that.