简体   繁体   中英

WebRequest.Create throws “Value cannot be null. Parameter name: str” exception

I wrote a wrapper around HttpWebRequest with the constructor :

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

when I pass a vaild url that works in 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

I get

System.ArgumentNullException occurred Message="Value cannot be null.\\r\\nParameter name: str" Source="mscorlib" ParamName="str" StackTrace: at 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) at System.Security.Permissions.FileIOPermission..ctor(FileIOPermissionAccess access, String path) at System.Uri.ParseConfigFile(String file, IdnScopeFromConfig& idnStateConfig, IriParsingFromConfig& iriParsingConfig) at System.Uri.GetConfig(UriIdnScope& idnScope, Boolean& iriParsing) at System.Uri.InitializeUriConfig() at System.Uri.InitializeUri(ParsingError err, UriKind uriKind, UriFormatException& e) at System.Uri.CreateThis(String uri, Boolean dontEscape, UriKind uriKind) at System.Uri..ctor(String uriString) at System.Net.WebRequest.Create(String requ estUriString)

Why is that ? how do i fix it ?

Unescape网址,然后再试一次。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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