0
var values = new NameValueCollection
{
    { "key", "key_edited_for_security" },
    { "image", Convert.ToBase64String(ms.ToArray()) }
};

byte[] response = w.UploadValues("https://api.imgur.com/2/upload.xml", values);

这工作得很好,关键来自几年前某人创建的另一个 stackoverflow 帖子(上传到 imgur.com),我已经在 imgur 注册了我的应用程序,但是当我使用我的客户端 ID 或客户端密码 ID 时,我得到错误 400(错误请求)。

4

1 回答 1

0

我确实测试了上面的代码,似乎工作正常

    static void Main(string[] args)
    {

        WebClient client = new WebClient();
        NameValueCollection values = new NameValueCollection();
        values["image"] = Convert.ToBase64String(File.ReadAllBytes(@"C:\test.jpg"));
        values["key"] = "the_key";
        byte[] responseBytes = client.UploadValues("https://api.imgur.com/2/upload.xml", values);
        string response = Encoding.Default.GetString(responseBytes);
        client.Dispose();
        /* Content of response 
        <?xml version="1.0" encoding="utf-8"?>
        <upload><image><name/><title/><caption/><hash>E63BcFm</hash><deletehash>zWO2xnca2co0VcB</deletehash><datetime>2013-02-15 23:15:45</datetime><type>image/jpeg</type><animated>false</animated><width>677</width><height>342</height><size>29513</size><views>0</views><bandwidth>0</bandwidth></image><links><original>http://i.imgur.com/E63BcFm.jpg</original><imgur_page>http://imgur.com/E63BcFm</imgur_page><delete_page>http://imgur.com/delete/zWO2xnca2co0VcB</delete_page><small_square>http://i.imgur.com/E63BcFms.jpg</small_square><large_thumbnail>http://i.imgur.com/E63BcFml.jpg</large_thumbnail></links></upload>
        */
    }
于 2013-02-15T23:18:06.363 回答