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

Send JSON or raw body #166

Closed
cklckl48 opened this issue Dec 11, 2014 · 15 comments
Closed

Send JSON or raw body #166

cklckl48 opened this issue Dec 11, 2014 · 15 comments

Comments

@cklckl48
Copy link

I'm trying to test a POST where the body type as follow:
{ "params":
{ "params1": 1,
"params2": 2}}

Can you give me any idea how to test it? thank you

@cpanato
Copy link

cpanato commented Dec 11, 2014

can you be more clear? i didn understood. What you would like to test?

@cklckl48
Copy link
Author

http request as below,

POST /111/rest/1/platform/1/sync HTTP/1.1
Host: 192.168.20.100:80
Authorization: Basic Z3Vlc3Q6MTIzNDU=
Content-Type: application/json
Cache-Control: no-cache
Postman-Token: f5bb12e0-8b64-9227-58a4-3ae4a51b1ca6

{ "params":
{ "params1": 1414576832033,
"params2": 1414576832033}}

I would like to post it to the url

Thank you for the help

@cklckl48
Copy link
Author

I wrote something like this , but it didnt work

var frisby = require('frisby');
var requestData = {
"params":
{"params1": 1414576832033,
"params2": 1414576832033,}};
frisby.create('TestPostSyncAndroid')
.post('http://192.168.20.100:80/111/rest/1/platform/1/sync', requestData, {
json: true
})
.auth('guest','11111')
.expectStatus(200)
.expectHeaderContains('content-type', 'application/json')
.expectJSONTypes({
success: Boolean,
responseData: Object,
deletes: Object,
timestamp: Number,
elements: Number
})
.expectJSON({
success: true,
elements: 1
})
.toss();

@cpanato
Copy link

cpanato commented Dec 12, 2014

you should do something like this: (if not work what is the error?)

var requestData = {
   "params": {
      "params1": 1414576832033,
      "params2": 1414576832033
   }
};

frisby.create('Should TestPostSyncAndroid')
   .post(http://192.168.20.100:80/111/rest/1/platform/1/sync,
      requestData,
      { json: true },
      { headers: { 'Content-Type': 'application/json', 'Authorization': <user user authorization> }})
   .expectStatus(200)
   .expectJSONTypes({})
   .expectJSON({})
 .toss();

@cklckl48
Copy link
Author

Thank you so much for the help , but the problem right now , it shows the status 302 instead of 200

@cklckl48
Copy link
Author

This is my code, it for sure something I did wrong

var frisby = require('frisby');
var requestData = {
"params": {
"param1": 1414576832033,
"param2": 1414576832033
}
};

            frisby.create('TestPostSyncAndroid')
            .post('http://192.168.20.100:80/111/rest/1/platform/1/syn',
                  requestData,
                  { json: true },
                  { headers: { 'Content-Type': 'application/json', 'Authorization': 'Basic Z3Vlc3Q6MTIzNDU=' }})
               .expectStatus(200)
    .expectHeaderContains('content-type', 'application/json')
             .toss();

@cpanato
Copy link

cpanato commented Dec 12, 2014

did you try send this request for example in the Postman app ? 302 is a response for found.

Try to add the .inspectJSON()

@cklckl48
Copy link
Author

Hi ,
Thank you for the help
I sent the request by postman, everything works correctly ,but when I tried to use frisby to test this post request , it gave to me 302 status instead of 200, maybe something I did wrong in the code

@cpanato
Copy link

cpanato commented Dec 12, 2014

try to use the .auth together

check how postman set the content-type. check if is in Raw or in x-www-form-urlencoded or something like that, then you will need change

@cklckl48
Copy link
Author

Thank you so much for the advice, I will try it on Monday when I am in the office , I will keep you update
Postman set the content-type is in Raw , this I am quite sure.

@cklckl48
Copy link
Author

Hi,
Sorry for the late reply , I am adding the auth , the code as follow, but the result now give me 202 instead of 302 ......do you have any suggestion ? thank you

var frisby = require('frisby');
var requestData = {
"params": {
"param1": 1414576832033,
"param2": 1414576832033
}
};
frisby.create('TestPostSyncAndroid')
.post('http://192.168.20.100:80/111/rest/1/platform/1/syn',
requestData,
{ json: true },
{ headers: { 'Content-Type': 'application/json', 'Authorization': 'Basic Z3Vlc3Q6MTIzNDU=' }})
.auth('guest','12345')
.expectStatus(200)
.expectHeaderContains('content-type', 'application/json')
.toss();

@cpanato
Copy link

cpanato commented Dec 16, 2014

your request was accepted.

maybe yo uneed talk with some developer whihc made the endpoint and check with him.
and you need check if you expected to receive htpp 200 or 202. alsio you might need validate the response if have.

@cklckl48
Copy link
Author

Thank you for the information
I was using swigger to post this request, it gave me back 200 status, but when I using frisby , it gave to me 202 or 302, I don´t know what happen with my code, I guess some parts are not correct

@bkhurshi
Copy link

bkhurshi commented Jan 2, 2015

#171 seems to be a similar issue. #167 seems to have the fix, but the issue was closed.

@vlucas
Copy link
Owner

vlucas commented Jul 26, 2017

This should be fixed in v0.8.5. Please update to v2 though and see if you still have this issue.

@vlucas vlucas closed this as completed Jul 26, 2017
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

4 participants