Here's an odd one that has come up a couple of times today.
I have a WPF app that does some posts to a server. I'm doing this using HttpWebRequest.Create. In this instance, the URL that is being used is hard-coded. Example:
Dim Request As HttpWebRequest = HttpWebRequest.Create("https://www.google.com/")
That's really all the code I can offer, the exception is being generated from within the HttpWebRequest.Create method. Running .Net 4.0 as far as I'm aware.
I do C# as well, so if you have a suggestion and that is your "native language" then shoot.
I've had a few asks so I thought I'd add to the rest of the surrounding code, but the line I've posted above is the line the exception is coming directly from. You'll see it in context below, but it isn't very helpful.
Private Function edatRequest() As CookieCollection
Dim Request As HttpWebRequest = HttpWebRequest.Create("https://www.google.com/")
With Request
.AllowAutoRedirect = False
.Method = "POST"
.Accept = "*/*"
.Headers.Add("Accept-Encoding:gzip,deflate")
.Headers.Add("Accept-Language:en-US,en;q=0.8")
.KeepAlive = True
.CookieContainer = Me.MyCredentials.MyCookies
.ContentLength = 0
.ContentType = "application/x-www-form-urlencoded; charset=UTF-8"
.Host = "https://www.google.com/"
.Headers.Add("Origin:https://www.google.com/")
.Referer = "https://wwww.google.com/"
.UserAgent = "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/38.0.2125.111 Safari/537.36"
End With
Dim Response As HttpWebResponse = Request.GetResponse
Dim ResponseReader As New StreamReader(Response.GetResponseStream)
Dim ResponseText As String = ResponseReader.ReadToEnd
Dim ReturnCookies As New CookieContainer
ReturnCookies.Add(Response.Cookies)
Return ReturnCookies
End Sub
EDIT: Adding some stack trace information from our error notifier:
The application has encountered an unhandled exeption and must
end. Please forward the following information to (our
department): System.UriFormatException: Invalid URI: The URI is
empty.
at System.Uri.CreateThis(String uri, Boolean dontEscape, UriKind
uriKind)
at System.Uri..ctor(String uriString)
at System.Net.WebRequest.Create(String requestUriString)
at AutoLib.Automation.edatRequest()
at AutoLib.Automation.LogIn()
at AutoLib.Automation.Submit(Request1 Request) <- not actually a 1 - generic sub
at AutoTool.MainWindow.GetAuto()
at AutoTool.MainWindow.Lambda$_21()
at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
at System.Threading.ExecutionContext.RunInternal(ExecutionContext
executionContext, ContextCallback callback, Object state, Boolean
preserveSyncCtx)
at System.Threading.ExecutionContext.Run(ExecutionContext
executionContext, ContextCallback callback, Object state, Boolean
preserveSyncCtx)
at System.Threading.ExecutionContext.Run(ExecutionContext
executionContext, ContextCallback callback, Object state)
at System.Threading.ThreadHelper.ThreadStart()
There you go.