C#: Handling WebClient “protocol violation”

前端 未结 2 1824
旧时难觅i
旧时难觅i 2020-12-03 17:14

I need to read a location in my Router, but I get the following exception -

ServerProtocolViolation \"The server committed a protocol violation. 
                    


        
2条回答
  •  被撕碎了的回忆
    2020-12-03 18:03

    Looks like the easiest way is including a .config file with your app containing the following:

    
    
    
    
    
    

    However it's also possible to do it within the code but it seems a little messy:

    http://social.msdn.microsoft.com/Forums/en-US/netfxnetcom/thread/ff098248-551c-4da9-8ba5-358a9f8ccc57

    Also note that the MSDN definition of that property is

    Setting this property ignores validation errors that occur during HTTP parsing.

    http://msdn.microsoft.com/en-us/library/system.net.configuration.httpwebrequestelement.useunsafeheaderparsing.aspx

    So I'd say it's fairly safe to use, although it does mention to only use it for backwards compatibility.

提交回复
热议问题