[SOLVED] What is wrong in my http request (method PUT)?

Hi all, I’m trying to use Blynk with STM32, so I trying to send http requests to the Blynk server.
GET method work fine, but PUT method causes error #500.

Below is my request to the cloud.blynk.cc:8080:

PUT /my_auth_token/pin/v1 HTTP/1.1
Host: cloud.blynk.cc
Content-Type: application/json

And this is response from the Blynk server:

HTTP/1.1 500 Internal Server Error
Connection: keep-alive
Content-Type: text/plain
Content-Length: 26

Error parsing body param.

What is wrong with my PUT request?

I could be wrong but I thought PUT was not yet available for the Blynk server and that it only currently works with a local server.

But how can I write pin value in such case?
By the way, PUT method described in the Blynk documentation: http://docs.blynkapi.apiary.io/#reference/0/pin-actions/write-pin-value

You can deploy a local server.

Yes, but it isn’t a solution.

Local servers are available for around $10 these days but if a local server isn’t an option then it is a waiting game. As I said maybe PUT is available on the Blynk server but whenever I have tried it, last time was a few days ago, I too get the error.

@r44083 with what tool do you do PUT request? Most probably you just escaping body value wrong.

@Dmitriy so PUT is available now for the Blynk server?

@Costas Yes, but we don’t announce it yet as still some works should be done here. (certificates, 80 port, etc). We don’t have time for that at the moment .

I use custom driver for CC3100. Before I send this request to the Blynk web server, I run simple TCP socket listener on my PC and connect MCU to this local TCP socket for listening my PUT request. It was exactly like in my first message in that forum thread. After that I just change IP to (cloud.blynk.cc) and port to 8080.

In addition, the GET request works correctly, so this indicates that the http connection works correctly.

My PUT request (one string) in C language looks like this:

"PUT /my_auth_token/pin/v1 HTTP/1.1\r\nHost: cloud.blynk.cc\r\nContent-Type: application/json\r\n[\"1\"]\r\n\r\n"

Is it correct?

I think you also need to specify port for host.
Host: cloud.blynk.cc:8080

I change request like you say but it still does not work (server response error #500). Now my PUT request is:

"PUT /my_auth_token/pin/v1 HTTP/1.1\r\nHost: cloud.blynk.cc:8080\r\nContent-Type: application/json\r\n[\"1\"]\r\n\r\n"

Please try also

["1"] instead of [\"1\"]

It is hard to say what exactly is wrong. As I’m not C guy and I has no clue how does that string parsed within your code. Could you please post all code for HTTP request? GET also would be helpful.

Hack with " need for inserting to the string raw " symbol, because standalone " symbol indicates end of string in C.
Also I tried with ['1'] - it isn’t working too.

Below is my GET http request which works fine:

"GET /my_auth_token/pin/v1 HTTP/1.1\r\nHost: cloud.blynk.cc\r\n\r\n"

Can you also tell why I should send requests on the 8080 port, whereas documentation says that I should use 8442 port without SSL/TLS or 8441 with SSL/TLS?

The problem is solved. Below is a correct PUT request:

PUT /your_auth_token/pin/v1 HTTP/1.1\r\nHost: cloud.blynk.cc\r\nContent-Type: application/json\r\nContent-Length: 7\r\n\r\n[\"255\"]\r\n

@r44083 suggest you change cloud.blynk.cc to blynk-cloud.com:8080 as .cc will be switched off soon as per the recent Announcement from Blynk.

@Costas we found the problem. Put request is bad formed and not according to specification. Should be

PUT /my_auth_token/pin/v1 HTTP/1.1\r\nHost: blynk-cloud.com\r\nContent-Type: application/json\r\n\r\n[\"1\"]\r\n

plus missing Content-Length

Could you please post all code for HTTP request?

Here is a simple code to build Blynk set/get HTTP requests:

#define BLYNK_SERVER_IP "" // blynk-cloud.com

    BLYNK_SERVER_PORT_SSL_TLS        = 8441, // SSL/TLS connection for hardware via Blynk binary protocol
    BLYNK_SERVER_PORT_PLAIN_TCP      = 8442, // Plain TCP connection for hardware via Blynk binary protocol
    BLYNK_SERVER_PORT_MUTUAL_SSL     = 8443, // Mutual authentication (mutual SSL) connection for mobile app
    BLYNK_SERVER_PORT_PLAIN_TCP_HTTP = 8080, // Plain TCP connection via HTTP
    BLYNK_SERVER_PORT_SSL_TLS_HTTPS  = 9443  // SSL/TLS connection via HTTPS

// My auth_token on the Blynk web server

void build_set_req(char *req_buff, size_t *req_size, uint8_t pin, int16_t val)
    uint8_t val_buff[10] = {};

    xsprintf(val_buff, "%d", val);

    xsprintf(req_buff, "PUT /%s/pin/v%d HTTP/1.1\r\nHost: %s\r\n"
        "Content-Type: application/json\r\nContent-Length: %d\r\n\r\n[\"%s\"]\r\n",
        BLYNK_AUTH_TOKEN, pin, BLYNK_SERVER_IP, strlen(val_buff) + strlen("[\"\"]"),

    *req_size = strlen(req_buff);

void build_get_req(char *req_buff, size_t *req_size, uint8_t pin)
    xsprintf(req_buff, "GET /%s/pin/v%d HTTP/1.1\r\nHost: %s\r\n\r\n",

    *req_size = strlen(req_buff);
1 Like