I
I
idin2020-02-22 01:18:58
go
idin, 2020-02-22 01:18:58

How to pass a carriage return character to url in Go so that a line break occurs in telegram?

Sending a get request:

url := "https://api.telegram.org/bot_id:AAHHaVdgdsfgR1UHrTfxfAZEAk/sendMessage?chat_id=12345&text=text \n новая строка"
resp, err := http.Get(url)

And if I pass \n then I get an error:
invalid control character in URL .

If \\n then I get a message in the cart:
text \n new line

If%2Fn then in the cart I get the message:
text \n new line

Answer the question

In order to leave comments, you need to log in

1 answer(s)
E
Evgeny Mamonov, 2020-02-22
@Izy

use url.QueryEscape

import "net/url"
...
text := url.QueryEscape("text \n новая строка")
requestURL := "https://api.telegram.org/bot_id:AAHHaVdgdsfgR1UHrTfxfAZEAk/sendMessage?chat_id=12345&text=" + text

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question