mzereba
mzereba

Reputation: 2517

Getting 400 Bad request when building JSON Object to send with POST

I am trying to build a JSON to send with a POST, but it seems that I am doing something wrong:

var encodedRdf = base64_encode(rdf);
var data = '{"path": path, "rdf": encodedRdf}';

This way I get 400 Bad Request error and it does't fire the REST at all.

Instead if I put hard coded strings as follows it works fine:

var encodedRdf = base64_encode(rdf);
var data = '{"path": "ppp", "rdf": "rrr"}';

Any ideas?

Thanks,

Upvotes: 0

Views: 279

Answers (2)

mzereba
mzereba

Reputation: 2517

This solved it.

   data: JSON.stringify(data),

Upvotes: 0

Angel Iliikov
Angel Iliikov

Reputation: 694

Your var data = '{"path": path, "rdf": encodedRdf}'; is not valid, the variables path and encodedRdf are not calculated and are passed like 'path' and 'encodedRdf'. Try passing like:

var data = {
    path: path,
    rdf: encodedRdf
}

Upvotes: 1

Related Questions