Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

POST JSON with extra (") at start and end #172

Closed
HugoSousa opened this issue Dec 23, 2014 · 8 comments
Closed

POST JSON with extra (") at start and end #172

HugoSousa opened this issue Dec 23, 2014 · 8 comments

Comments

@HugoSousa
Copy link

So, I'm trying to test a POST request like this:

frisby.create('POST login details')
  .post(TEST + '/login',
  {
    username: "aaa",
    password: "9834876dcfb05cb167a5c24953eba58c4ac89b1adf57f28f2f9d09af107ee8f0"
  },
  { json: true },
  { headers: { 'Content-Type': 'application/json' }})
  .inspectJSON()
.toss();

But, instead of a response 200, I'm getting a 401, because JSON isn't parsed correctly. I tried on Postman and it behaves correctly, returning 200, and after printing the body on the server it is like this (just an example, not the full body):

{ "username": "aaa" }

But with frisby it is:

"{ \"username\": \"aaa\" }"

I think the quotation marks at the start and the end of the body are the problem, and server can't parse the JSON correctly. Am I doing something wrong?

@AnirudhaAgashe
Copy link

I am facing the same problem. Did you find any solution ?
#171

@HugoSousa
Copy link
Author

The trick on issue #167 fixed it for me. I've seen that reverting 'request' dependency back to 2.49 instead of 2.51 also fixes it, but I didn't try that.

@danlesage
Copy link

I have encountered the same problem. Reverting request.js back to 2.49 works for me.

@AnirudhaAgashe
Copy link

I didn't revert back to 2.51. I just changed
outgoing.body = JSON.stringify(data);
to
outgoing.body = data;
on line 389 of frisby.js
Now its working. Still not sure whether its right way to go.

@vlucas
Copy link
Owner

vlucas commented Feb 9, 2015

Update to Frisby v0.8.5 - this is resolved.

@vlucas vlucas closed this as completed Feb 9, 2015
@vimukthi101
Copy link

getting the same issue with "version": "2.0.16" when sending the post request. Request is assigned to a variable and the variable is set in the frisby post command.

get the request :

var contents = fs.readFileSync(conf.tempFile, 'utf8').split('\n');
for(var i=0; i < contents.length - 1; i++){
var records = contents[i].split('|');
run_test(records[0],records[1],records.slice(2),i+1);
}

send the request :

var response = frisby
.post(conf.url,requestToFire)
.catch(err => {
logger.error(err);
})
.expect('status', 200)
.expect('header', 'Content-Type', 'application/json')
.done();

sending request taken from pcap :

"{"applicationId":"APP_000409","password":"eca5f1be454dc6744524b89010b40b5b","message":"hello world","destinationAddresses":["tel:AZ1101HXstW4OYuw4QQfODWKWPzL7dqtj49mywemJ6F5Mw+Np3WrFV6euLMjSgGx4hsQX6LQ0irL74IR673S0cNWWJA=="],"deliveryStatusRequest":"0"}"

@H1Gdev
Copy link
Collaborator

H1Gdev commented Jun 8, 2018

@vimukthi101

I think requestToFire is string.

How about this ?

.post(conf.url,JSON.parse(requestToFire))

@vimukthi101
Copy link

yes I got the issue resolved by using the above (Y)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants