I want to send post request with body like this "<p> He is πŸ˜€</p>"

When I send the request, the emoji become gibberish.
I believe that encoding it would fix. For instance, this

He is \uD83D\uDE00</p> will work.

Does anyone know how can encode this? or if you know anything else I can do to get this working?

Thanks in advance

Please show us the exact client code that makes this request.

How do you know your code does not work? What do you expect?

    payloadB, err := json.Marshal(payload)
      if err != nil {
     return nil, err

    req, err := http.NewRequest("POST", uri, bytes.NewReader(payloadB))
    req.SetBasicAuth(username, password)
    req.Header.Set("Content-Type", "application/json")

I want to receive the emoji instead of this Γ°ΒŸΒ˜Β€

The snippet you’ve posted does not contain the emoji. What exactly is payload?

This is the payload:

{ "string": "<p>Barry πŸ˜€</p>"}

Not the payload but the exact content of payload in this line:

payloadB, err := json.Marshal(payload)

It is very hard to help you if you don’t provide the information necessary to understand and reproduce your problem.

This the data. Sorry for the delay and for not providing this before hand

type Data struct {
    TextData    string `json:"text"`
s := "{<p>Barry πŸ˜€ πŸ‡</p>}"
payload := TextData{
TextData: s
payloadB, err := json.Marshal(payload)
1 Like

So far I can’t reproduce your problem. Consider this: https://play.golang.org/p/G59ENK7WxhV

The call of json.Unmarshal with the result of json.Marshal as the input returns the expected TextData. The emoji is fine.

So please show us what you do with the encoded payloadB. How do you post it? How do you know that the server you post it to receives gibberish?

When i send the request to my end point, I handle the request and render it on html page.
and the render looks like this <p>Barry Γ°ΒŸΒ˜Β€</p> so even the p tag is not rendered as it should be.

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.