[英]The remote server returned an error: (404) Not Found. In GetResponse()
I am trying to call a HTML page from Mandrill. 我正在尝试从Mandrill调用HTML页面。 The HTML below is not being displayed in console. 控制台中未显示以下HTML。 //HTML Template I am calling //我正在调用的HTML模板
<!DOCTYPE html>
<tr>
<td>This is a test email from Mandrill</td>
</tr>
</table>
</body>
</html>
//Console app //控制台应用
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);
}
}
}
That is because the web page does not exist. 那是因为网页不存在。 You would get the same result if if tried to open it in a browser (unless it responds to a GET but not a POST) -- I just tried it myself to confirm, it is giving an http 404 error at the address you supply. 如果尝试在浏览器中打开它,您将得到相同的结果(除非它响应GET而不是POST)-我只是亲自尝试确认,它在您提供的地址上显示了HTTP 404错误。
The URL you are trying to access - http://smtp.mandrillapp.com/test-email - is an API Endpoint. 您尝试访问的URL- http ://smtp.mandrillapp.com/test-email-是API端点。 According to the docs here - http://help.mandrill.com/entries/24486133-Does-Mandrill-have-a-test-mode-or-sandbox- you will need to generate a new Test API Key for testing emails and then authenticate your access in your C# code before attempting to post to that endpoint. 根据此处的文档-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.