Vb.net 如何在Visual Basic 2013的DirectCast中使用字符串?

Vb.net 如何在Visual Basic 2013的DirectCast中使用字符串?,vb.net,visual-studio-2010,visual-studio-2013,json.net,directcast,Vb.net,Visual Studio 2010,Visual Studio 2013,Json.net,Directcast,我尝试使用以下代码为Json执行DirectCast- 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)

我尝试使用以下代码为Json执行DirectCast-

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())
问题是,只有当我将电子邮件id硬编码到URL中时,上述方法才有效。e、 g
DirectCast(“http://localhost/json.php?id=abcd@gmail.com”,HttpWebRequest)
。当尝试获取电子邮件id作为变量时,我收到以下错误-

无法将“String”类型的值转换为 “System.Net.HttpWebRequest”


请帮助我完成这项工作。

不是从某物到其他一切的转换工具。如果
DirectCast(URL,HttpWebRequest)
不起作用,我高度怀疑
DirectCast(“http://localhost/json.php?id=abcd@gmail.com”,HttpWebRequest)
正在运行。你可能想再检查一遍。@roryap谢谢你提醒我再检查一遍。我忘了在DirectCast(WebRequest.Create(URL),HttpWebRequest)中添加
WebRequest.Create(URL)
。谢谢。我正要发布同样的内容,我忘了在
DirectCast(WebRequest.Create(URL),HttpWebRequest)
中添加
WebRequest.Create(URL)
。谢谢,我一定会的。我正在等待5分钟的堆栈溢出时间限制完成:)
request = WebRequest.Create(URL)