【发布时间】:2014-01-19 07:58:55
【问题描述】:
我正在尝试从 Mandrill 调用 HTML 页面。下面的 HTML 未显示在控制台中。 //我正在调用的HTML模板
<!DOCTYPE html>
<tr>
<td>This is a test email from Mandrill</td>
</tr>
</table>
</body>
</html>
//控制台应用
static void Main(string[] args)
{
var request =
WebRequest.Create("https://mandrillapp.com/templates/preview?id=test-email") as HttpWebRequest;
request.Method = "POST";
request.ContentType = "text/plain";
byte[] byteData = Encoding.ASCII.GetBytes("");
request.ContentLength = byteData.Length;
using (Stream postStream = request.GetRequestStream())
{
postStream.Write(byteData, 0, byteData.Length);
}
using (HttpWebResponse resp = request.GetResponse() as HttpWebResponse)
{
using (var reader = new StreamReader(resp.GetResponseStream(), Encoding.UTF8))
{
string value = reader.ReadToEnd();
Console.WriteLine(value);
}
}
}
【问题讨论】:
-
你还期待别的吗?您的代码看起来不错,并且您尝试访问的服务器可能不会期待此类请求。 (旁注 url 看起来更像 SMTP 端点而不是 HTTP)。