I'm building an API for Pixiv and so far I've managed to complete the login process and searching by tags works as well.
Now I want to download the image on the selected webpage. At first I was getting some certificate errors. I fixed that by temporarily ignoring certificate validation.
Then a very interesting thing happened... If Fiddler was running in the background - the response was successfully received and I was able to download the image. No problems, whatsoever.
But when the Fiddler was NOT running, the remote server returned the 421 error code.
Things I've already tried:
HttpWebRequest imagerequest = (HttpWebRequest)WebRequest.Create(imgLink);
imagerequest.Host = $"i.pximg.net";
imagerequest.UserAgent = USER_AGENT;
imagerequest.Accept = "image/webp,image/*,*/*;q=0.8";
imagerequest.Referer = post.PostLink;
imagerequest.Headers.Add("Accept-Encoding", "gzip, deflate, sdch, br");
using (var imageresponse = (HttpWebResponse)imagerequest.GetResponse())
using (var imagestream = imageresponse.GetResponseStream())
imagecontent = imagestream.ReadStream();
GET https://i.pximg.net/img-original/img/2014/02/09/00/10/03/41485846_p0.jpg HTTP/1.1
User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/54.0.2840.99 Safari/537.36
Accept-Encoding: gzip, deflate, sdch, br
Seems like I was just blind. The "imgLink" had the wrong hostname set the entire time, but I didn't notice it because the hostnames were so similar. I guess Fiddler was automatically fixing that for me...
Next time I will be sure to triple-check the hostname. Thanks for for all the help.