小编Cam*_*rde的帖子

在ASP .NET MVC 6项目中使用System.Net.Mail

我在ASP NET 5项目中创建一个简单的模拟邮件发件人时遇到了麻烦.

这里的方法:

    public static Task SendMail(string Email, string Subject, string Body)
    {
        SmtpClient client = new SmtpClient();
        client.DeliveryMethod = SmtpDeliveryMethod.SpecifiedPickupDirectory;
        client.PickupDirectoryLocation = "C:\\TMP";

        MailAddress from = new MailAddress("jane@contoso.com", "Jane " + (char)0xD8 + " Clayton", System.Text.Encoding.UTF8);
        MailAddress to = new MailAddress(Email);

        MailMessage message = new MailMessage(from, to);
        message.Body = Body;
        message.BodyEncoding = System.Text.Encoding.UTF8;
        message.Subject = Subject;
        message.SubjectEncoding = System.Text.Encoding.UTF8;

        client.Send(message);
        message.Dispose();

        return Task.FromResult(0);
    }
Run Code Online (Sandbox Code Playgroud)

我已经包含了依赖项'System.Net.Mail',但工具提示说该库在DNX 4.5.1中可用,但在DNX Core 5.0中不可用,并且项目将无法编译.

在我的project.json中有:

"frameworks": {
    "dnx451": { },
    "dnxcore50": { }
}
Run Code Online (Sandbox Code Playgroud)

.net system.net.mail smtpclient asp.net-core-mvc mailkit

11
推荐指数
2
解决办法
4673
查看次数

Playframework WSRequest POST登录

我使用Java和Playframework 1.2.3创建了一个Web爬虫.现在,我想抓取一些受经典登录/密码表单保护的网页.

事实上,这就像做这个游戏测试:

@Test
public void someTestOfASecuredAction() {
    Map<String, String> loginUserParams = new HashMap<String, String>();
    loginUserParams.put("username", "admin");
    loginUserParams.put("password", "admin");
    Response loginResponse = POST("/login", loginUserParams);

    Request request = newRequest();
    request.cookies = loginResponse.cookies; // this makes the request authenticated
    request.url = "/some/secured/action";
    request.method = "POST";
    request.params.put("someparam", "somevalue");
    Response response = makeRequest(request);
    assertIsOk(response); // Passes!
}
Run Code Online (Sandbox Code Playgroud)

但不是通过播放生成的网站,而是与外部网站.

所以,我设法使用播放网络服务器来做到这一点:

Map<String,String> params = new HashMap<String, String>();
params.put( "telecom_username", 
            Play.configuration.getProperty("telecom.access.user") );

params.put( "telecom_password", 
            Play.configuration.getProperty("telecom.access.pass") );

HttpResponse response = WS.url(loginUrl)
                        .setParameters(params)
                        .followRedirects(true)
                        .post();
Run Code Online (Sandbox Code Playgroud)

当我这样做时,如果我查看response.getString(),我发现在继续之前设置了cookie的重定向页面,但是,如果我得到一个受保护的页面,我仍然没有登录.它就像是cookie从未设置过,并且HttpResponse对象没有任何与cookie相关的功能,就像之前测试代码中的响应一样.

我也尝试过ws.url()上的authenticate()方法,但它也不起作用.

我真的不知道我正在尝试做什么是通过使用播放网络服务器,但我可以使用这个^^的帮助

非常感谢 …

java post login playframework

3
推荐指数
1
解决办法
5958
查看次数