创建Web请求时出现System.UriFormatException错误

时间:2018-12-20 22:52:54

标签: c# asp.net

我需要从用户那里获取url作为输入,并从输入网站获取所有数据(以搜索某些内容)

代码:

public partial class _Default : System.Web.UI.Page
{
    private string StringFromTheInput;

    protected void Page_Load(object sender, EventArgs e)
    {
        StringFromTheInput = urToSubmit.Value;
        var request_ = (HttpWebRequest)WebRequest.Create(StringFromTheInput);
        WebResponse response = request_.GetResponse();
        Stream data = response.GetResponseStream();
        string html = String.Empty;
        using (StreamReader sr = new StreamReader(data))
        {
           html = sr.ReadToEnd();
        }
   }
}

和输入<input type="text" name="url" id="urToSubmit" runat="server" />

但是在建立var request_ = (HttpWebRequest)WebRequest.Create(StringFromTheInput);时遇到上述错误 如何根据需要更改它? 谢谢!

0 个答案:

没有答案