繁体   English   中英

远程服务器返回错误:(404)找不到。 在GetResponse()中

[英]The remote server returned an error: (404) Not Found. In GetResponse()

我正在尝试从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);
        }
     }
}

那是因为网页不存在。 如果尝试在浏览器中打开它,您将得到相同的结果(除非它响应GET而不是POST)-我只是亲自尝试确认,它在您提供的地址上显示了HTTP 404错误。

您尝试访问的URL- http ://smtp.mandrillapp.com/test-email-是API端点。 根据此处的文档-http: //help.mandrill.com/entries/24486133-Does-Mandrill-have-a-test-mode-or-sandbox-,您将需要生成新的Test API密钥以测试电子邮件和然后在尝试发布到该终结点之前,使用C#代码对您的访问进行身份验证。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM