C#SSL基本接入认证 [英] C# SSL Basic Access Authentication

查看:650
本文介绍了C#SSL基本接入认证的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想从第三方索取报告,他们需要基本访问认证通过POST:


 客户端应用程序必须使用基本接入认证
发送的用户名和密码。


有人能指出我在正确的方向或建议如何与C#做到这一点的教程?

编辑:我确实看到<一个href=\"http://stackoverflow.com/questions/450380/login-to-the-page-with-httpwebrequest/595318#595318\">this帖子但有两个答案,我不知道如果多数民众赞成什么,我需要做什么或哪一个是preferred方法。


解决方案

假设你使用的WebRequest,您可以将CredentialCache您的要求:

 的NetworkCredential NC =新的NetworkCredential(用户,密码);
        CredentialCache CC =新CredentialCache();
        cc.Add(www.site.com,443,基本,NC);
        WebRequest的请求= WebRequest.Create(https://www.site.com);
        request.Credentials = CC;
        要求preAuthenticate = TRUE。
        request.Method =POST;        //其他请求属性填写在这里,如内容        WebResponse类respose = request.GetResponse();

I want to request reports from a third party and they require "Basic Access Authentication" via POST:

Your client application must use Basic Access Authentication 
to send the user name and password.

Can someone point me in the right direction or recommend a tutorial on how to do this with C#?

Edit: I did see this post but there are two answers and I'm not sure if thats what I need to do or which one is the preferred method.

解决方案

Assuming you use a WebRequest, you attach a CredentialCache to your request:

        NetworkCredential nc = new NetworkCredential("user", "password");
        CredentialCache cc = new CredentialCache();
        cc.Add("www.site.com", 443, "Basic", nc);


        WebRequest request = WebRequest.Create("https://www.site.com");
        request.Credentials = cc;
        request.PreAuthenticate = true;
        request.Method = "POST";

        // fill in other request properties here, like content

        WebResponse respose = request.GetResponse();

这篇关于C#SSL基本接入认证的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆