【问题标题】:The remote server returned an error: (404) Not Found. In GetResponse()远程服务器返回错误:(404) Not Found。在 GetResponse() 中
【发布时间】: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)。

标签: c# mandrill


【解决方案1】:

那是因为网页不存在。如果尝试在浏览器中打开它(除非它响应 GET 但不响应 POST),您会得到相同的结果——我只是自己尝试确认,它在您提供的地址处给出了 http 404 错误。

【讨论】:

    【解决方案2】:

    您尝试访问的 URL - http://smtp.mandrillapp.com/test-email - 是一个 API 端点。根据此处的文档 - http://help.mandrill.com/entries/24486133-Does-Mandrill-have-a-test-mode-or-sandbox-,您需要 generate a new Test API Key 来测试电子邮件,然后在尝试发布到该端点之前在您的 C# 代码中验证您的访问权限。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-09-20
      • 2018-04-17
      • 1970-01-01
      • 2019-12-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-07-03
      相关资源
      最近更新 更多