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帖子,(Uploading to imgur.com),我在imgur here注册了我的应用程序,但是当我使用my客户端ID或客户端密码ID我收到错误400(错误请求)。
答案 0 :(得分: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>
*/
}