How to use String in DirectCast in Visual Basic 2013?

521 Views Asked by At

I was trying to DirectCast for Json, using the following code -

Dim EmailId as String
Dim URL as String
EmailId = txtEmailId.Text
URL = "http://localhost/json.php?id=" & EmailId

request = DirectCast(URL, HttpWebRequest)
response = DirectCast(request.GetResponse(), HttpWebResponse)
reader = New StreamReader(response.GetResponseStream())

The problem is, the above mentioned method only works if I hard code Email id into URL. e.g DirectCast("http://localhost/[email protected]", HttpWebRequest). When try to get Email id as variable I get following error -

Value of type 'String' cannot be converted to 'System.Net.HttpWebRequest'.

Please help me to make this work.

1

There are 1 best solutions below

2
djv On BEST ANSWER
request = WebRequest.Create(URL)