vb.netvisual-studio-2010visual-studio-2013json.netdirectcast

How to use String in DirectCast in Visual Basic 2013?


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/json.php?id=abcd@gmail.com", 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.


Solution

  • request = WebRequest.Create(URL)