当我对代码中的url进行硬编码时,它可以工作。我想获取主机名并附加请求。它给出了这个错误,
无效 URI :URI方案无效。
说明:执行当前Web请求期间发生了未处理的异常。请查看堆栈跟踪以获取有关错误及其源自代码的位置的更多信息。
Exception Details: System.UriFormatException: Invalid URI: The URI scheme is not valid.
Source Error:
Line 44: string request = url.Scheme + "//" + url.Host + ":" + url.Port +"/accounts1/asp2netbridge.asp?sessVar=";
Line 45:
Line 46: HttpWebRequest _myRequest = (HttpWebRequest)WebRequest.Create(new Uri(request + sessionValue));
Line 47: _myRequest.ContentType = "text/html";
Line 48: _myRequest.Credentials = CredentialCache.DefaultCredentials;
以下是代码:
Uri url = HttpContext.Current.Request.Url;
string request = url.Scheme + "//" + url.Host + ":" + url.Port +"/accounts1/asp2netbridge.asp?sessVar=";
HttpWebRequest _myRequest = (HttpWebRequest)WebRequest.Create(new Uri(request + sessionValue));
答案 0 :(得分:1)
在“//”
之前添加“:”string request = url.Scheme +“://”+ url.Host +“:”+ url.Port + “/ accounts1 / asp2netbridge.asp sessVar =?”;