WebRequest.Create抛出“Value不能为null。参数名称:str”异常

时间:2009-09-30 11:39:50

标签: .net exception httpwebrequest

我用构造函数编写了一个围绕HttpWebRequest的包装器:

    public MyHttpRequest(string requestUrl)
    {
        this.webRequest = (HttpWebRequest)WebRequest.Create(requestUrl);
    }

当我传递一个在IE中工作的虚拟网址时

  

http://www.google.co.il/search?q=%D7%A9%D7%9E%D7%A8+%D7%97%D7%A1%D7%95%D7%9F&ie=utf-8&oe=utf-8&aq=t&rls=org.mozilla:en-US:official&client=firefox-a

我得到了

  

发生了System.ArgumentNullException     Message =“Value不能为null。\ r \ nParameter name:str”     来源= “mscorlib程序”     PARAMNAME = “STR”     堆栈跟踪:          在System.Security.Permissions.FileIOPermission.HasIllegalCharacters(String [] str)          at System.Security.Permissions.FileIOPermission.AddPathList(FileIOPermissionAccess access,AccessControlActions control,String [] pathListOrig,Boolean checkForDuplicates,Boolean needFullPath,Boolean copyPathList)          在System.Security.Permissions.FileIOPermission..ctor(FileIOPermissionAccess访问,字符串路径)          在System.Uri.ParseConfigFile(String file,IdnScopeFromConfig& idnStateConfig,IriParsingFromConfig& iriParsingConfig)          在System.Uri.GetConfig(UriIdnScope& idnScope,Boolean& iriParsing)          在System.Uri.InitializeUriConfig()          在System.Uri.InitializeUri(ParsingError错误,UriKind uriKind,UriFormatException& e)          在System.Uri.CreateThis(String uri,Boolean dontEscape,UriKind uriKind)          在System.Uri..ctor(String uriString)          在System.Net.WebRequest.Create(String requestUriString)

为什么?我该如何解决?

1 个答案:

答案 0 :(得分:1)

取消网址,然后重试。