问题
Aight, before I get redirected to some post that doesn't answer this. I would like to state that I am creating a program AUTO UPDATER. And how it works is that if it sees 1.0.0.0 then fine, 1.0.0.1 then update.
So I went to Ghostbin, a site that allows you to change text on there and I linked it up to my code. Thing is, it gave me this error. I don't know how to fix it.
Exception: The remote server returned an error: (406) Not Acceptable
Here is my code.
private void button1_Click(object sender, EventArgs e)
{
if (!new WebClient().DownloadString("https://ghostbin.com/paste/odmbf")
.Contains("1.0.0.0"))
{
MessageBox.Show("You are running the latest version!", "No Update",
MessageBoxButtons.OK, MessageBoxIcon.Information);
}
else
{
if (MessageBox.Show("New Update! Would you like to update?", "Yay!",
MessageBoxButtons.YesNo, MessageBoxIcon.Information) ==
System.Windows.Forms.DialogResult.Yes)
{
Process.Start("...");
}
}
}
回答1:
Ghostbin doesn't seem to accept the WebClient.
Fake it to appear as a browser using
wc.Headers.Add("user-agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/55.0.2883.87 Safari/537.36");
回答2:
Found the answer. Use pastebin instead. they have an edit option where you can edit a raw file!
来源:https://stackoverflow.com/questions/41393035/ghostbin-exception-the-remote-server-returned-an-error-406-not-acceptable