Ian,

Hugh Myrie might be expecting to see something like this:

https://go.dev/play/p/7TlD5R1C0oX

Peter

On Tuesday, July 2, 2024 at 9:53:41 PM UTC-4 Ian Lance Taylor wrote:

On Tue, Jul 2, 2024 at 5:29 PM Hugh Myrie <hugh....@gmail.com> wrote:

When I change the %s to %q in the print function I see the special 
characters in their Hexadecimal representations.

See below:

0011020240702\x1d02017580000001030085245467021.00Y00000000000050072     
2024070200000000000000000\x1cDG\x1cDI00\x1cE700000000\x1cG1200       
\x1cG2X \x1cG310\x1cG4E79   \x03


I am using the original code (JSON).

How do I then change them back to the actual characters?


If you see the characters with %q, then they are also there with %s.  But 
since they aren't printable characters, you aren't seeing them.

To put it another way: what do you expect to see?

Ian


 

On Tuesday, July 2, 2024 at 7:15:36 PM UTC-4 Ian Lance Taylor wrote:

1) Please send Go code as plain text, not as an image.  Anybody can read 
plain text.  Images are hard to read.  Thanks.

2) What do you see if you change the %s to %q in the fmt.Printf call?

Ian

On Tue, Jul 2, 2024 at 3:40 PM Hugh Myrie <hugh....@gmail.com> wrote:

The original Go function is shown below. Initially, a JSON-encoded string 
is sent from the client. The first print function is used to view the 
output after decoding.


func SendClaim(w http.ResponseWriter, r *http.Request) {
    //  strEcho := "Halo"
    servAddr := tcpAddress

    type Resp struct {
        Status string `json:"status"`
        Reply  string `json:"reply"`
    }
    type Claim struct {
        ClaimInfo string `json:"claiminfo"`
    }

    var params Claim

    erx := json.NewDecoder(r.Body).Decode(&params)
    if erx != nil {
        http.Error(w, erx.Error(), http.StatusBadRequest)
        fmt.Println("Error occurs here")
        log.Printf(erx.Error())
        return
    }
    fmt.Printf("Claims: %s \n", params)
    //  policy := params.CardNo //r.FormValue("cardno")
    //  log.Println("policy # ", policy)

    tcpAddr, err := net.ResolveTCPAddr("tcp", servAddr)
    if err != nil {
        println("ResolveTCPAddr failed:", err.Error())
        respondWithError(w, http.StatusBadRequest, err.Error())
        return
    }

    data := params.ClaimInfo
    //  printr := r.FormValue("printer")

    fmt.Println(data)
    conn, err := net.DialTCP("tcp", nil, tcpAddr)
    if err != nil {
        println("Dial failed:", err.Error())
        respondWithError(w, http.StatusBadRequest, err.Error())
        return
    }

    _, err = conn.Write([]byte(data))
    if err != nil {
        println("Write to server failed:", err.Error())
        respondWithError(w, http.StatusBadRequest, err.Error())
        return
    }

    reply := make([]byte, 1024)

    _, err = conn.Read(reply)
    if err != nil {
        println("Write to server failed:", err.Error())
        respondWithError(w, http.StatusBadRequest, err.Error())
        return
    }

    resp := Resp{}
    println("reply from server=", string(reply))
    resp.Status = "response"
    resp.Reply = string(reply)

    respondWithJSON(w, http.StatusOK, resp)

    conn.Close()
}


On Tuesday, July 2, 2024 at 9:28:01 AM UTC-4 Hugh Myrie wrote:

Copying the result to notepad confirms the missing special characters.. 

I'll try your suggestion.

Thanks.

<http://www.avg.com/email-signature?utm_medium=email&utm_source=link&utm_campaign=sig-email&utm_content=webmail>
Virus-free.www.avg.com 
<http://www.avg.com/email-signature?utm_medium=email&utm_source=link&utm_campaign=sig-email&utm_content=webmail>
 
<#m_6273277082335633664_m_-4475757952619024099_m_7810203444138361032_m_3329966587656473292_m_4334311486301273828_DAB4FAD8-2DD7-40BB-A1B8-4E2AA1F9FDF2>

On Tue, Jul 2, 2024 at 8:33 AM 'Dan Kortschak' via golang-nuts <
golan...@googlegroups.com> wrote:

On Mon, 2024-07-01 at 12:03 -0700, Hugh Myrie wrote:
> I am trying to preserve special characters (group separators and
> field separators) when reading the request body from a POST request.
> 
> When I do a dumpRequest I am able to see the special characters (Hex
> Format, for example: \x1c or \x03). I am sending the data from the
> client as text/plain.
> 
> I have tried sending the data as JSON and using the decoder in Go. I
> have also tried using Base64 and decoding in go accordingly. I have
> tried json.unmarshal to decode the incoming JSON data. However, in
> every instance the special characters are removed.
> 
> I need the special characters to be preserved so I can send the data
> for further processing. I need the special characters not the
> hexadecimal representation.
> 
> I am able to see the actual data being sent to the Go server. I also
> tried encoding the data from the client side.
> 
> Your help would be greatly appreciated.

This looks to be working as expected. https://go.dev/play/p/fqLPbsMKaOm

How are you seeing the bytes being missing?


-- 
You received this message because you are subscribed to a topic in the 
Google Groups "golang-nuts" group.
To unsubscribe from this topic, visit 
https://groups.google.com/d/topic/golang-nuts/8cLWTdxHQCI/unsubscribe.
To unsubscribe from this group and all its topics, send an email to 
golang-nuts...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/9cf1e4d31b68f7601839a450e1a9aa572458e756.camel%40kortschak.io
.



-- 
http://www.jaxtr.com/blessed_hope

-- 

You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an 
email to golang-nuts...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/6fd2520e-a7e3-43ed-89d5-dc96419d8a89n%40googlegroups.com
 
<https://groups.google.com/d/msgid/golang-nuts/6fd2520e-a7e3-43ed-89d5-dc96419d8a89n%40googlegroups.com?utm_medium=email&utm_source=footer>
.

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an 
email to golang-nuts...@googlegroups.com.

To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/55ed1944-c470-432a-800d-11ac48324310n%40googlegroups.com
 
<https://groups.google.com/d/msgid/golang-nuts/55ed1944-c470-432a-800d-11ac48324310n%40googlegroups.com?utm_medium=email&utm_source=footer>
.

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/b311aa8b-4363-49a4-bd4a-922493165a1an%40googlegroups.com.

Reply via email to