[SOLVED] Curl(?) differences linux/windows

The following snippet from the mattermost-website works with curl 7.37.0 under opensuse 42.3:

“curl -v -X POST -d ‘payload={“text”: “Hello, this is some text\nThis is more text. :tada:”}’ http://my.ser.ver/hooks/MyCorrectHook

Using curl 7.53.1 under Windows7 I get the following error:

{“id”:“web.incoming_webhook.parse.app_error”,“message”:“Konnte eingehende Daten
nicht verarbeiten”,“detailed_error”:"",“request_id”:“c6okeourhjf4zgygygmwhgthcw”
,“status_code”:400}* Connection #0 to host my.ser.ver left intact

The german string “Konnte eingehende Daten nicht verabeiten” means “couldn’t process/parse incoming data”.

Do I have to mask the special signs {}"’ ?

hjb

Looks like a quote issue to me:

“curl -v -X POST -d ‘payload={“text”: “Hello, this is some text\nThis is more text. :tada:”}’ http://my.ser.ver/hooks/MyCorrectHook”

versus:

curl -v -X POST -d 'payload={"text": "Hello, this is some text\nThis is more text. :tada:"}' http://my.ser.ver/hooks/MyCorrectHook

Aside from the different library used to communicate(socket/ssl) from one OS to another, it should work the same as on linux

I see no difference in your examples besides the outer double qoutes in the first example; but they were not part of the command string.

Regarding the communication library:
This is the log snippet from the successful (linux) send:

[2017/08/30 08:57:24 CEST] [DEBG] POST - /api/v4/users/status/ids
[2017/08/30 08:57:34 CEST] [DEBG] POST - /hooks/nfxohn48ijdajpuu6awg93j6sw
[2017/08/30 08:57:34 CEST] [DEBG] Eingehender Webhook erhalten. Inhalt={“text”: “Hello, this is some text\nThis is more text. :tada:”}
[2017/08/30 08:57:57 CEST] [DEBG] POST - /api/v4/users/login
[2017/08/30 08:57:57 CEST] [DEBG] GET - /api/v4/users/me/teams/members
[2017/08/30 08:57:57 CEST] [DEBG] GET - /api/v4/users/me/teams/unread
[2017/08/30 08:57:57 CEST] [DEBG] GET - /api/v4/users/me/preferences

And here the snippet from the failing (windows7) send:

[2017/08/30 09:19:11 CEST] [DEBG] GET - /api/v4/websocket
[2017/08/30 09:19:11 CEST] [EROR] Websocket-Verbindungsfehler: websocket: not a websocket handshake: ‘upgrade’ token not found in ‘Connection’ header
[2017/08/30 09:19:11 CEST] [EROR] /api/v4/websocket:connect code=500 rid=stbzyrq3r78ume4iid5kpd7xuy uid=on5xfhwizigdfgx74pa3dqjfxe ip=10.45.64.158 Failed to upgrade websocket connection [details: ]
[2017/08/30 09:19:18 CEST] [DEBG] POST - /hooks/nfxohn48ijdajpuu6awg93j6sw
[2017/08/30 09:19:18 CEST] [DEBG] Eingehender Webhook erhalten. Inhalt=
[2017/08/30 09:19:18 CEST] [EROR] /hooks/nfxohn48ijdajpuu6awg93j6sw:HandleIncomingWebhook code=400 rid=8e6htxciy3fab8cpo3uqhhwyih uid= ip=10.45.64.158 Unable to parse incoming data [details: ]
[2017/08/30 09:19:24 CEST] [DEBG] POST - /api/v4/users/status/ids

Maybe it gives you some hints?

Server is mattermost 4.x, latest version as of Monday.

Thank You
Hermann-Josef Beckers

By communication library, I meant that windows and linux use different libraries not about mattermost, that was to illustrate the difference curl have from windows to linux.

No, if you look closely the inner single and double quotes in YOUR example looks different then mine.

See how they look different:

That will often fail on prompt.

Yes I see what you mean. But I think I’m using the right quotes:

> curl -v -d 'payload={"text": "Hello"}' http://my.ser.ver/hooks/nfxohn48ijdajpuu6awg93j6sw

Seems I can’t upload a screenshot oder hexdump of the above line. The single quotes I’m using have a hex value of 27 and the double quotes are hex 22.
The windows curl complains “curl: (3) [globbing] unmatched close brace/bracket in column 6”.
If one counts multiple spaces as 1 column, that is the first “-” (hyphen ?). Substituting “-” with
"/" treats them als (malformed) urls.

Thanks
Hermann-Josef Beckers

Can you try using the -g switch to disable globbing and see if that works for you? Or alternatively escape the double-quotes.

using “-g” curl complains about an illegal port number:

executing tmp2.cmd

curl -g -v -d ‘payload={“text”: “Hel
lo this is some text\nThis is more text. :tada:”}’ myhostname/hooks/nfxohn48ijdajpuu6awg93j6sw

  • Rebuilt URL to: Hello this is some text\nThis is more text. :tada:}'/
  • Illegal port number
  • Closing connection -1
    curl: (3) Illegal port number
  • timeout on name lookup is not supported
  • Trying a.b.c.xxx…
  • TCP_NODELAY set
  • Connected to xxx.kreis-steinfurt.lokal (a.b.c.xxx) port 80 (#0)

POST /hooks/nfxohn48ijdajpuu6awg93j6sw HTTP/1.1
Host: xxx.kreis-steinfurt.lokal
User-Agent: curl/7.53.1
Accept: /
Content-Length: 15
Content-Type: application/x-www-form-urlencoded

  • upload completely sent off: 15 out of 15 bytes
    < HTTP/1.1 400 Bad Request
    < Server: nginx/1.4.6 (Ubuntu)
    < Date: Thu, 31 Aug 2017 05:56:17 GMT
    < Content-Type: application/json
    < Content-Length: 179
    < Connection: keep-alive
    < Access-Control-Allow-Origin:
    < X-Request-Id: 3qn34pacb7g68d1q3ese1pmwha
    < X-Version-Id: 4.1.0.4.1.0.d4dab482fe7337cd6e0d9619e0685522.false
    <
    {“id”:“web.incoming_webhook.parse.app_error”,“message”:“Konnte eingehende Daten
    nicht verarbeiten”,“detailed_error”:“”,“request_id”:“3qn34pacb7g68d1q3ese1pmwha”
    ,“status_code”:400}* Connection #0 to host xxx.kreis-steinfurt.lokal left i
    ntact

Regarding escaping the double-qoutes: Using “^” (caret) as escape changes nothing.
Using unix-style “\” every string separated by spaces after the first string
'payload={\"Text\":
is treated as a url.

Thanks for your help
Hermann-Josef Beckers

Further testing:

Using double quotes (") for the outer quotes and single quotes (’) for the inner strings, mattermost receives the webhook content but is still unable to parse the content:

[2017/08/31 11:07:18 CEST] [DEBG] POST - /hooks/nfxohn48ijdajpuu6awg93j6sw
[2017/08/31 11:07:18 CEST] [DEBG] Eingehender Webhook erhalten. Inhalt={‘text’: 'Hello this is some text\nThis is more text. '}
[2017/08/31 11:07:18 CEST] [EROR] /hooks/nfxohn48ijdajpuu6awg93j6sw:HandleIncomingWebhook code=400 rid=b1huj9g6mtg9dx7ekrz8kd533o uid= ip=10.45.64.158 Unable to parse incoming data [details: ]

It seems that Windows curl doesn’t like single quotes. This works:

curl -g -H "Content-type: application/json" -X POST -d "{\"text\":\"Patrick This is a line of line of text.\"}"

Putting every string in double quotes and escape any double quotes within with a \.
And it needs the header line.

1 Like

Nicely found, indeed… You could also write it as:

curl -i -d "payload={\"text\":\"This is a line of\n line of text.\"}" url

EDIT:
Also added to the docs a NOTE for windows users, it should be updated as soon as MM team approves it :wink: