【发布时间】:2014-07-21 14:11:37
【问题描述】:
我正在尝试使用以下代码为 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 时才有效。例如DirectCast("http://localhost/json.php?id=abcd@gmail.com", HttpWebRequest)。当尝试将电子邮件 ID 作为变量时,我收到以下错误 -
“字符串”类型的值无法转换为 'System.Net.HttpWebRequest'。
请帮助我完成这项工作。
【问题讨论】:
-
DirectCast不是从某事物到其他事物的转换工具。 -
如果
DirectCast(URL, HttpWebRequest)不工作,我高度怀疑DirectCast("http://localhost/json.php?id=abcd@gmail.com", HttpWebRequest)工作。您可能需要仔细检查。 -
@roryap 感谢您提醒我仔细检查。我忘了在
DirectCast(WebRequest.Create(URL), HttpWebRequest)中添加WebRequest.Create(URL)。谢谢。
标签: vb.net visual-studio-2010 visual-studio-2013 json.net directcast