Answer the question
In order to leave comments, you need to log in
C#. VK API. Why is there an empty photo field in the JSON response when trying to upload a photo?
Hello, there was a need to upload a photo to the vk.com wall.
According to this documentation, I send a post request to the URL received in Point 1 in the following way:
public static HttpWebResponse PostMethod(string postedData, string postUrl)
{
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(postUrl);
request.Method = "POST";
request.Credentials = CredentialCache.DefaultCredentials;
UTF8Encoding encoding = new UTF8Encoding();
var bytes = encoding.GetBytes(postedData);
request.ContentType = "application/json";
request.ContentLength = bytes.Length;
using (var newStream = request.GetRequestStream())
{
newStream.Write(bytes, 0, bytes.Length);
newStream.Close();
}
return (HttpWebResponse)request.GetResponse();
}
var webClient = new WebClient();
byte[] imageData = webClient.DownloadData("http://cs5530.vk.me/u43529379/-6/m_b9515ce2.jpg");
//изображение для примера
{"server":425829,"photo":"[]","hash":"dd26fe93801ca464d320a0a6e35f7e8a"}
Answer the question
In order to leave comments, you need to log in
I figured it out. Tried curl to fill in the photo and it still flooded. Python doesn't know how out of the box Content-Type: multipart/form-data; send, after installing the required library, everything worked.
The working header for my post request is:
> User-Agent: curl/7.30.0
> Host: cs312918.vk.com
> Accept: */*
> Content-Length: 56798
> Expect: 100-continue
> Content-Type: multipart /form-data; boundary=----------------------c16a5ea66209
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question