vb.net 不支持 URI 格式
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/19260754/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
URI formats are not supported
提问by Lulzsec Owner
I'm basically making a mass email sender in C# using Microsoft Visual Studio, the idea is that it uses real email accounts via SMTP to send the emails so they are not marked as spam, but I keep getting the error:
我基本上是使用 Microsoft Visual Studio 在 C# 中制作大量电子邮件发件人,其想法是它通过 SMTP 使用真实的电子邮件帐户来发送电子邮件,因此它们不会被标记为垃圾邮件,但我不断收到错误消息:
URI formats are not supported.
Basically the code below retrieves the list of email accounts from my website but throws the error above.
基本上,下面的代码从我的网站检索电子邮件帐户列表,但会引发上述错误。
String[] saUsernames = File.ReadAllLines(@"http://mywebsite.com/test/accounts.txt");
I've tried loading the file locally and it works fine so i cant figure out what the issue is, anyone got any ideas as I'm well and truly confused
我试过在本地加载文件,它工作正常,所以我无法弄清楚问题是什么,任何人都有任何想法,因为我真的很困惑
edit: heres the whole script as something else may be causing the error, ive removed some of the links to my site,etc as its a project in development and i dont want to give away many clues
编辑:这里是整个脚本,因为其他东西可能导致错误,我删除了一些指向我网站的链接等,因为它是一个正在开发的项目,我不想透露很多线索
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Net;
using System.Net.Mail;
using System.Threading;
using System.IO;
namespace NecroBomber
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
int iTimeOutValue = 100;
int iSentAmount = 0;
SmtpClient client = new SmtpClient();
MailMessage mail = new MailMessage();
String[] saUsernames = File.ReadAllLines(@"http://example.com/accounts.txt");
WebClient wcUpdates = new WebClient();
string sMasterPassword = "testpassword";
string sLastUsername = "";
int iTimeOutWebRequest = 0;
private void btnClick(object sender, EventArgs e)
{
Button btnCurrent = ((Button)sender);
if (btnCurrent.Tag.ToString() == "SendMail")
{
prbSentStatus.Maximum = ((int)nudAmount.Value * saUsernames.Length);
Thread tStart = new Thread(SendMail);
tStart.Start();
}
else if (btnCurrent.Tag.ToString() == "AddAccount")
{
AddNewAccount();
}
else if (btnCurrent.Tag.ToString() == "Update")
{
try
{
if (wcUpdates.DownloadString(@"http://example.com/version.txt") != "1.0.0")
{
if (dlgSaveUpdate.ShowDialog() == DialogResult.OK)
{
wcUpdates.DownloadFile(@"http://example.com/new.exe", dlgSaveUpdate.FileName);
}
}
else
{
MessageBox.Show("Your version is up to date!", "Information!");
}
}
catch
{
}
}
}
private void SendMail()
{
int iToSend = Convert.ToInt32(nudAmount.Value);
for (int i = 0; i < saUsernames.Length; i++)
{
GrabMailDetails(i);
client.Credentials = new NetworkCredential(saUsernames[i], sMasterPassword);
if (saUsernames[i] != sLastUsername)
{
if (saUsernames[i].EndsWith("@yahoo.com"))
{
client.Host = "smtp.mail.yahoo.com";
client.Port = 587;
client.EnableSsl = false;
}
else if (saUsernames[i].EndsWith("@gmail.com"))
{
client.Host = "smtp.gmail.com";
client.Port = 25;
client.EnableSsl = true;
}
else if (saUsernames[i].EndsWith("@hotmail.co.uk"))
{
client.Host = "smtp.live.com";
client.Port = 587;
client.EnableSsl = true;
}
else if (saUsernames[i].EndsWith("@outlook.com"))
{
client.Host = "smtp.live.com";
client.Port = 587;
client.EnableSsl = true;
}
else if (saUsernames[i].EndsWith("@hotmail.com"))
{
client.Host = "smtp.live.com";
client.Port = 587;
client.EnableSsl = true;
}
else if (saUsernames[i].EndsWith("@aol.co.uk"))
{
client.Host = "smtp.aol.com";
client.Port = 587;
client.EnableSsl = true;
}
else if (saUsernames[i].EndsWith("@aol.com"))
{
client.Host = "smtp.aol.com";
client.Port = 587;
client.EnableSsl = true;
}
}
else
{
}
sLastUsername = saUsernames[i];
for (int x = 0; x < iToSend; x++)
{
try
{
client.Send(mail);
iSentAmount++;
}
catch
{
MessageBox.Show("Maximum emails today sent from this SMTP server has been reached.\nAccount name: " + sLastUsername, "Error!");
goto JMP;
}
}
JMP: ;
}
}
private void GrabMailDetails(int count)
{
try
{
mail = new MailMessage();
mail.Body = tbBody.Text;
mail.Subject = tbSubject.Text;
mail.From = new MailAddress(saUsernames[count]);
mail.To.Add(tbTarget.Text);
{
}
if (rbHigh.Checked)
{
mail.Priority = MailPriority.High;
}
else if (rbLow.Checked)
{
mail.Priority = MailPriority.Low;
}
else if (rbNorm.Checked)
{
mail.Priority = MailPriority.Normal;
}
}
catch
{
}
}
private void AddNewAccount()
{
String[] saCurrentAccounts = File.ReadAllLines(@"Accounts.txt");
string sAddNewAccount = "";
for (int i = 0; i < saCurrentAccounts.Length; i++)
{
sAddNewAccount += saCurrentAccounts[i] + Environment.NewLine;
}
}
private void timeUpdate_Tick(object sender, EventArgs e)
{
prbSentStatus.Value = iSentAmount;
lblEmailSentCount.Text = "Emails Sent: " + iSentAmount;
iTimeOutWebRequest++;
if (iTimeOutWebRequest == iTimeOutValue)
{
}
}
private void Form1_Load(object sender, EventArgs e)
{
timeUpdate.Start();
lblMultiple.Text = "x " + saUsernames.Length;
this.Text = "test - " + Environment.UserName;
}
private void pictureBox1_Click(object sender, EventArgs e)
{
}
private void button2_Click(object sender, EventArgs e)
{
if (wcUpdates.DownloadString(@"update.com/version") != "1.0.0")
{
if (dlgSaveUpdate.ShowDialog() == DialogResult.OK)
{
MessageBox.Show("Updating LulzBomber. Please wait a few minutes", "Information!");
wcUpdates.DownloadFile(@"update.com/version", dlgSaveUpdate.FileName);
}
}
else
{
MessageBox.Show("Your version is up to date!", "Information!");
}
}
private void button3_Click(object sender, EventArgs e)
{
MessageBox.Show("Created by ***", "About");
}
}
}
采纳答案by JuStDaN
File.ReadAllLines does not support a direct URI path as stated in the error message (although it is puzzling how it is working locally), just allocate your path to a string then use that in the request.
File.ReadAllLines 不支持错误消息中所述的直接 URI 路径(尽管令人费解的是它在本地的工作方式),只需将您的路径分配给一个字符串,然后在请求中使用它。
string path = @"http://mywebsite.com/test/accounts.txt";
String[] saUsernames = File.ReadAllLines(path);
Edit: You could ditch the @ as there are no characters to escape in your string and just use your original line.
编辑:您可以放弃@,因为您的字符串中没有要转义的字符,只需使用您的原始行。
回答by Chris Ruck
File.ReadAllLines does not support the http schema such as http.
File.ReadAllLines 不支持 http 模式,例如 http。
Try instead:
试试吧:
string content;
using (WebClient client = new WebClient())
{
content = client.DownloadString("http://example.com/accounts.txt");
}
'content' will contain the complete contents of the file. Splitting the content into an array is trivial using the string.Split() function.
'content' 将包含文件的完整内容。使用 string.Split() 函数将内容拆分为数组是微不足道的。
Note: WebClient can also reference local files from disk if referenced as such:
注意:如果这样引用,WebClient 也可以从磁盘引用本地文件:
@"file://c:\folder\account.txt"

