Zorro and Mattermost by http_send()?

Posted By: Grat

Zorro and Mattermost by http_send()? - 05/21/21 13:04

Hi,

do you anybody know, how to send msg to Mattermost?

In the python I use this code:
Code
    headers = {'Content-Type': 'application/json',}
    try:
        main()
    except:
        values =  '{ "text": "Exception on re4mt4"}'
        requests.post('https://4xcd.cloud.mattermost.com/hooks/pmjiwyb............x', headers=headers, data=values) 


but in the Zorro this not work. My code:
Code


void sendMTS(){
    
    string Header="{'Content-Type': 'application/json',}";   
    string Code = "{ \"text\": \"Exception on Zorro :\"}";
    string URL = "https://4xcd.cloud.mattermost.com/hooks/pmj...........x";
    int handle=http_send (URL,  Code, Header);
    printf("\nSTAT: %d",http_status(handle));   // return 173
    http_free(handle);
}

function run() {
    printf("Run testing..");
    sendMTS();
    wait(1000);
    quit("");
}
Posted By: AndrewAMD

Re: Zorro and Mattermost by http_send()? - 05/21/21 14:29

Http headers do not use the formatting you show.
https://datatracker.ietf.org/doc/html/rfc2616#section-4.2
https://en.wikipedia.org/wiki/List_of_HTTP_header_fields
Quote
Header fields are colon-separated key-value pairs in clear-text string format, terminated by a carriage return (CR) and line feed (LF) character sequence.

More like this:
Code
"key1:value1\r\nkey2:value2\r\nkey3:value3"
Posted By: Grat

Re: Zorro and Mattermost by http_send()? - 05/22/21 08:54

finally - this example work:

Code
void sendMTS(string cIn){
  
    string Header="Content-Type:application/json";   
    string Code = strf("{\r\n\"text\": \"Error - %s\"\r\n}",cIn);
    string URL = "https://4xcd.cloud.mattermost.com/hook/.....";
    int handle=http_send (URL,  Code, Header);
    printf("\nSTAT: %d",http_status(handle));

  http_free(handle);
}

function run() {
    printf("Run testing..");
    sendMTS("Test");
    wait(1000);
    quit("");
}
© 2024 lite-C Forums