0

my name is Juraj Čarnogurský. Notice the Č character. I want to send my name from the one server to API. But my last name gets replaced with this

"firstName":"Juraj","lastName":"
                                arnogurský"}}

which ruins the JSON format.

I am using NodeJS btw.

How to encode my last name to the form suitable for network transfer?

EDIT

I do this:

const jsonrpc = require('jsonrpc-lite');
const requestHttp = require('request');

and this:

let obj = jsonrpc.request(id, method, params);

requestHttp({
    uri: 'http://localhost:3001/api?data=' + JSON.stringify(obj),
    method: 'GET',
}, (error, response, body) => { ...

and as id I send '1' as method I send addCustomer and as params I send this:

{
     customerId: senderID,
     facebookId: senderID,
     firstName: context.user.firstName,
     lastName: context.user.lastName,
}

where context.user.lastName is Čarnogurský

theonlygusti
  • 11,032
  • 11
  • 64
  • 119
durisvk
  • 927
  • 2
  • 12
  • 24

2 Answers2

1

You already realised that

uri: 'http://localhost:3001/api?data=' + JSON.stringify(obj)

had to be replaced with

uri: 'http://localhost:3001/api?',
qs: {
  data: JSON.stringify(obj),
}

This is because all URLs can only use ASCII:

URLs are written only with the graphic printable characters of the US-ASCII coded character set.

Your name contains characters outside of the ASCII set.

theonlygusti
  • 11,032
  • 11
  • 64
  • 119
0

I've made it work by doing this:

requestHttp({
        uri: 'http://localhost:3001/api?',
        qs: {
            data: JSON.stringify(obj),
        },
        method: 'GET',
}, (error, response, body) => { ...

instead of this:

requestHttp({
     uri: 'http://localhost:3001/api?data=' + JSON.stringify(obj),
     method: 'GET',
}, (error, response, body) => { ...
durisvk
  • 927
  • 2
  • 12
  • 24