本文整理汇总了C#中System.Net.NetworkCredential.GetCredential方法的典型用法代码示例。如果您正苦于以下问题:C# System.Net.NetworkCredential.GetCredential方法的具体用法?C# System.Net.NetworkCredential.GetCredential怎么用?C# System.Net.NetworkCredential.GetCredential使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Net.NetworkCredential
的用法示例。
在下文中一共展示了System.Net.NetworkCredential.GetCredential方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Main
static void Main(string[] args)
{
// create a service object
RallyServiceService service = new RallyServiceService();
service.Url = "https://rally1.rallydev.com/slm/webservice/1.42/RallyService";
// login to service using HTTP Basic auth
System.Net.NetworkCredential crediential =
new System.Net.NetworkCredential("[email protected]", "secret");
Uri uri = new Uri(service.Url);
System.Net.ICredentials credentials = crediential.GetCredential(uri, "Basic");
service.Credentials = credentials;
service.PreAuthenticate = true;
// Configure the service to maintain an HTTP session cookie
service.CookieContainer = new System.Net.CookieContainer();
Workspace workspace = null;
// Make the web service call
//---------------------------
Defect defect = new Defect();
service.create(defect);
// Name is required
defect.Name = "bad defect";
defect.Description = "trouble";
//Create defect on the server
CreateResult createResult = service.create(defect);
if (hasErrors(createResult))
{
// something went wrong
Console.WriteLine("Could not create defect result:");
printWarningsErrors(createResult);
}
else
{
// look at the object returned from create()
defect = (Defect)createResult.Object;
Console.WriteLine("Created defect, ref = " + [email protected]);
}
}
示例2: Send
///<summary>
/// 邮件的发送
///</summary>
public void Send()
{
try
{
if (mMailMessage != null)
{
mSmtpClient = new SmtpClient();
//mSmtpClient.Host = "smtp." + mMailMessage.From.Host;
mSmtpClient.Host = this.mSenderServerHost;
mSmtpClient.Port = this.mSenderPort;
mSmtpClient.UseDefaultCredentials = false;
mSmtpClient.EnableSsl = this.mEnableSsl;
if (this.mEnablePwdAuthentication)
{
System.Net.NetworkCredential nc = new System.Net.NetworkCredential(this.mSenderUsername, this.mSenderPassword);
//mSmtpClient.Credentials = new System.Net.NetworkCredential(this.mSenderUsername, this.mSenderPassword);
//NTLM: Secure Password Authentication in Microsoft Outlook Express
mSmtpClient.Credentials = nc.GetCredential(mSmtpClient.Host, mSmtpClient.Port, "NTLM");
}
else
{
mSmtpClient.Credentials = new System.Net.NetworkCredential(this.mSenderUsername, this.mSenderPassword);
}
mSmtpClient.DeliveryMethod = System.Net.Mail.SmtpDeliveryMethod.Network;
mSmtpClient.Send(mMailMessage);
}
}
catch (Exception ex)
{
Console.WriteLine(ex.ToString());
}
}
示例3: Send
/// <summary>
/// 邮件的发送
/// </summary>
/// <returns>true:发送成功</returns>
public bool Send()
{
if (!GetMailSetting.IsEnable)
{
return false;
}
bool flag = false;
try
{
if (mMailMessage != null)
{
mSmtpClient = new SmtpClient();
mSmtpClient.Host = this.mSenderServerHost;
mSmtpClient.Port = this.mSenderPort;
mSmtpClient.UseDefaultCredentials = false;
mSmtpClient.EnableSsl = this.mEnableSsl;
if (this.mEnablePwdAuthentication)
{
System.Net.NetworkCredential nc = new System.Net.NetworkCredential(this.mSenderUsername, this.mSenderPassword);
mSmtpClient.Credentials = nc.GetCredential(mSmtpClient.Host, mSmtpClient.Port, "NTLM");
}
else
{
mSmtpClient.Credentials = new System.Net.NetworkCredential(this.mSenderUsername, this.mSenderPassword);
}
mSmtpClient.DeliveryMethod = System.Net.Mail.SmtpDeliveryMethod.Network;
mSmtpClient.Send(mMailMessage);
flag = true;
}
}
catch (Exception ex)
{
//TODO:异常处理
}
return flag;
}
示例4: Send
///<summary>
/// 添加附件
///</summary>
///<param name="attachmentsPath">附件的路径集合,以分号分隔</param>
//public void AddAttachments(string attachmentsPath)
//{
// string[] path = attachmentsPath.Split(';'); //以什么符号分隔可以自定义
// Attachment data;
// ContentDisposition disposition;
// for (int i = 0; i < path.Length; i++)
// {
// data = new Attachment(path[i], MediaTypeNames.Application.Octet);
// disposition = data.ContentDisposition;
// disposition.CreationDate = File.GetCreationTime(path[i]);
// disposition.ModificationDate = File.GetLastWriteTime(path[i]);
// disposition.ReadDate = File.GetLastAccessTime(path[i]);
// mMailMessage.Attachments.Add(data);
// }
//}
///<summary>
/// 邮件的发送
///</summary>
public SMSResponse Send(MailMessage mailMessage)
{
SMSResponse response = new SMSResponse() { ResponseData = "邮件参数设置错误", statusCode = "201" };
try
{
if (mailMessage != null)
{
mSmtpClient = new SmtpClient();
//mSmtpClient.Host = "smtp." + mMailMessage.From.Host;
mSmtpClient.Host = this.mSenderServerHost;
mSmtpClient.Port = this.mSenderPort;
mSmtpClient.UseDefaultCredentials = false;
mSmtpClient.EnableSsl = this.mEnableSsl;
if (this.mEnablePwdAuthentication)
{
System.Net.NetworkCredential nc = new System.Net.NetworkCredential(this.mSenderUsername, this.mSenderPassword);
//mSmtpClient.Credentials = new System.Net.NetworkCredential(this.mSenderUsername, this.mSenderPassword);
//NTLM: Secure Password Authentication in Microsoft Outlook Express
mSmtpClient.Credentials = nc.GetCredential(mSmtpClient.Host, mSmtpClient.Port, "NTLM");
}
else
{
mSmtpClient.Credentials = new System.Net.NetworkCredential(this.mSenderUsername, this.mSenderPassword);
}
mSmtpClient.DeliveryMethod = System.Net.Mail.SmtpDeliveryMethod.Network;
mSmtpClient.Send(mailMessage);
// send successfully.
response.statusCode = "200";
}
}
catch (Exception e)
{
// send failed.
response.statusCode = "202";
response.InnerException = e;
response.ResponseData = "邮件发送失败";
}
return response;
}