简体   繁体   English

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

[英]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.

相关问题 远程服务器返回错误 (404) 未找到。 在 system.net.httpwebrequest.getresponse() - the remote server returned an error (404) not found. at system.net.httpwebrequest.getresponse() HttpWebRequest引发“ 404远程服务器返回错误:(404)未找到。” - HttpWebRequest throws “The remote server returned an error: (404) Not Found.” for 404 Picasa API返回“远程服务器返回错误:(404)Not Found。” - Picasa API returns “The remote server returned an error: (404) Not Found.” WebDriverManager - &#39;远程服务器返回错误:(404)未找到。&#39; - WebDriverManager - 'The remote server returned an error: (404) Not Found.' 远程服务器返回错误:(404)找不到。 使用Facebook图形API时 - The remote server returned an error: (404) Not Found. when using facebook graph api 远程服务器返回错误:(404) 未找到。 谷歌在 C# 中的实现 - The remote server returned an error: (404) Not Found. google implentation in c# 远程服务器返回错误:(404)找不到-HttpWebResponse - The remote server returned an error: (404) Not Found - HttpWebResponse C#HttpWebRequest.GetResponse()返回错误:(404)找不到 - c# HttpWebRequest.GetResponse() returned an error: (404) Not Found BrowserMob 代理 - 远程服务器返回错误:(404) 未找到 - BrowserMob Proxy - The remote server returned an error: (404) Not Found 服务器返回错误:找不到404 - The server returned an error: 404 not found
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM