【发布时间】:2009-05-25 14:27:52
【问题描述】:
我正在尝试使用 C# 中的 WebRequest 对站点执行 POST。我发布到的站点是一个 SMS 站点,messagetext 是 URL 的一部分。为了避免 URL 中出现空格,我调用 HttpUtility.Encode() 对其进行 URL 编码。
但我不断收到 URIFormatException - “无效的 URI:无法确定 URI 的格式” - 当我使用与此类似的代码时:
string url = "http://www.stackoverflow.com?question=a sentence with spaces";
string encoded = HttpUtility.UrlEncode(url);
WebRequest r = WebRequest.Create(encoded);
r.Method = "POST";
r.ContentLength = encoded.Length;
WebResponse response = r.GetResponse();
当我调用 WebRequest.Create() 时发生异常。
我做错了什么?
【问题讨论】:
标签: c# exception httpwebrequest