简体   繁体   English

Uri无效:Uri方案无效

[英]Invalid Uri: The Uri scheme is not valid

I am trying to make a connection via HttpWebRequest. 我试图通过HttpWebRequest建立连接。 I am reading url links from a text file. 我正在从文本文件中读取url链接。 However, I am getting 'System.UriFormatException' error. 但是,我收到'System.UriFormatException'错误。

I have tried to add http:// in front of the url links in my text file. 我试图在我的文本文件中的url链接前面添加http://。 But the result is the same. 但结果是一样的。

What can be the solution? 什么可以解决方案?

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). 如果只在从文件中读取值时发生错误,而在直接分配给string变量时才会发生错误,那么我猜测有多余字符被读取(引号,转义字符,回车符/换行符等) 。

Try reading the first value into a string , and then comparing that to what you expect in the explicit string value. 尝试将第一个值读入string ,然后将其与显式string值中的预期值进行比较。 Any differences should be obvious after that. 之后任何差异都应该是显而易见的。

Without seeing code it's impossible to tell what you're trying to do. 没有看到代码,就无法分辨出你想要做什么。 But you can start by looking at the Message property of the UriFormatException class. 但您可以从查看UriFormatException类的Message属性开始。 Message is a string that explains the reason for the exception. Message是一个解释异常原因的字符串。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM