R
R
rybamoeymechty2014-02-08 21:58:23
ASP.NET
rybamoeymechty, 2014-02-08 21:58:23

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();
        }

where postedData is a JSON string containing a "photo" field and a value in the form of a byte[], which is filled in like this:
var webClient = new WebClient();
byte[] imageData = webClient.DownloadData("http://cs5530.vk.me/u43529379/-6/m_b9515ce2.jpg");
//изображение для примера

postUrl - received as a result of requests to api url
in response comes:
{"server":425829,"photo":"[]","hash":"dd26fe93801ca464d320a0a6e35f7e8a"}

why is the photo field , which should contain the id of the uploaded photo, empty?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
S
SevaUA, 2014-02-11
@SevaUA

I have the same problem, only python code

S
SevaUA, 2014-02-14
@SevaUA

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 question

Ask a Question

731 491 924 answers to any question