Uploading to imgur.com

前端 未结 3 418
名媛妹妹
名媛妹妹 2020-12-13 16:01

Imgur is a image uploading website who offers an API to upload

My code looks exactly like the PHP code they provide as an example. however, in their php code they ar

3条回答
  •  心在旅途
    2020-12-13 16:41

    I Guess that the dtb solution is deprecated

        using (var w = new WebClient())
        {
            var values = new NameValueCollection
        {
            {"image", Convert.ToBase64String(imageData)},
            {"type", "base64"}
        };
    
            w.Headers.Add("Authorization", "Client-ID xxxxxxxxx");
           var response = w.UploadValues("https://api.imgur.com/3/image", values);
        }
    

    another way to do:

            HttpWebRequest request = (HttpWebRequest)WebRequest.Create("https://api.imgur.com/3/image");
            request.Headers.Add("Authorization", "Client-ID xxxxxxx");
            request.Method = "POST";
    
            ASCIIEncoding enc = new ASCIIEncoding();
            string postData = Convert.ToBase64String(imageData);
            byte[] bytes = enc.GetBytes(postData);
    
            request.ContentType = "application/x-www-form-urlencoded";
            request.ContentLength = bytes.Length;
    
            Stream writer = request.GetRequestStream();
            writer.Write(bytes, 0, bytes.Length);
    
            HttpWebResponse response = (HttpWebResponse)request.GetResponse();
    

提交回复
热议问题