Coder Social home page Coder Social logo

POST request frisby about frisby HOT 11 CLOSED

vlucas avatar vlucas commented on August 29, 2024
POST request frisby

from frisby.

Comments (11)

vlucas avatar vlucas commented on August 29, 2024 1

Your Frisby test should look like this:

frisby.create('testAddUser')
.post('http://root:123456@localhost/payCard/Api/User', {
    userName : 'newApi',
    Password : '123456',
    installationId : 1,
    cityId : 2,
}), { json: true })
.inspectJSON()
.inspectBody()
.toss()

As for your PHP code, it's best to build an array and then run the whole array though json_encode, like this:

$jsonData = array();

// blah blah
$jsonData['status'] = array('StatusMSG' => 'Invalid JSON', 'Code' => 20);

// something else
$jsonData['foo'] = 'bar';

// then ONCE at the end of the script
echo json_encode($jsonData);

from frisby.

moses-gangipogu avatar moses-gangipogu commented on August 29, 2024

thank you sir it has helped me alot

from frisby.

moses-gangipogu avatar moses-gangipogu commented on August 29, 2024

hello sir
try this its giving me the 406 HTTP error status

/*****************this delete rquest works perfectly
/

* Tests -> DELETE delete an existing user based on user User_Id
*/
frisby.create('testDeleteUser')
.delete('http://localhost/payCard/Api/User/22')
.expectStatus(200)
.expectHeaderContains('content-type', 'application/json')
.expectJSON('status',{
StatusMSG: "SUCCESS",
Code: '1'
})
.toss();

/******but the request with json data into it is not working and giving 406 error

/**
* Tests -> POST add a new user
*/
frisby.create('testAddUser')
.post('http://localhost/payCard/Api/User', {
userName : 'newApi',
Password : '123456',
installationId : 1,
cityId : 2,
}, { json: true })
.inspectJSON()
.inspectBody()
.expectStatus(200)
.expectHeaderContains('content-type', 'application/json')
.expectJSON('status',{
StatusMSG: "SUCCESS",
Code: '1'

})
.toss();

/*******************output

  1. Frisby Test: testAddUser
    [ POST http://localhost/payCard/Api/User ]
    Message:
    Expected 406 to equal 200.
    Stacktrace:
    Error: Expected 406 to equal 200.
    at null. (/var/www/frisby/lib/frisby.js:449:42)
    at null. (/var/www/frisby/lib/frisby.js:1026:43)
    at Timer.listOnTimeout as ontimeout

  2. Frisby Test: testAddUser
    [ POST http://localhost/payCard/Api/User ]
    Message:
    Expected 'text/html; charset=iso-8859-1' to contain 'application/json'.
    Stacktrace:
    Error: Expected 'text/html; charset=iso-8859-1' to contain 'application/json'.
    at null. (/var/www/frisby/lib/frisby.js:474:67)
    at null. (/var/www/frisby/lib/frisby.js:1026:43)
    at Timer.listOnTimeout as ontimeout

  3. Frisby Test: testAddUser
    [ POST http://localhost/payCard/Api/User ]
    Message:
    Error: Error parsing JSON string: Unexpected '<'
    Given:

<title>406 Not Acceptable</title>

Not Acceptable

An appropriate representation of the requested resource /payCard/Api/User could not be found on this server.

Available variants:

  • User.php , type application/x-httpd-php

Apache/2.2.22 (Ubuntu) Server at localhost Port 80

Stacktrace:
Error: Error parsing JSON string: Unexpected '<'
Given:

<title>406 Not Acceptable</title>

Not Acceptable

An appropriate representation of the requested resource /payCard/Api/User could not be found on this server.

Available variants:

  • User.php , type application/x-httpd-php

Apache/2.2.22 (Ubuntu) Server at localhost Port 80
at _jsonParse (/var/www/frisby/lib/frisby.js:1150:11)
at null.<anonymous> (/var/www/frisby/lib/frisby.js:606:20)
at null.<anonymous> (/var/www/frisby/lib/frisby.js:1026:43)
at Timer.listOnTimeout [as ontimeout] (timers.js:110:15)
  1. Frisby Test: testAddUser
    [ POST http://localhost/payCard/Api/User ]
    Message:
    Error: Error parsing JSON string: Unexpected '<'
    Given:
<title>406 Not Acceptable</title>

Not Acceptable

An appropriate representation of the requested resource /payCard/Api/User could not be found on this server.

Available variants:

  • User.php , type application/x-httpd-php

Apache/2.2.22 (Ubuntu) Server at localhost Port 80

Stacktrace:
Error: Error parsing JSON string: Unexpected '<'
Given:

<title>406 Not Acceptable</title>

Not Acceptable

An appropriate representation of the requested resource /payCard/Api/User could not be found on this server.

Available variants:

  • User.php , type application/x-httpd-php

Apache/2.2.22 (Ubuntu) Server at localhost Port 80
at _jsonParse (/var/www/frisby/lib/frisby.js:1150:11)
at Frisby.<anonymous> (/var/www/frisby/lib/frisby.js:862:30)
at Frisby.<anonymous> (/var/www/frisby/lib/frisby.js:892:8)
at null.<anonymous> (/var/www/frisby/lib/frisby.js:1057:18)
at Timer.listOnTimeout [as ontimeout] (timers.js:110:15)

Finished in 0.141 seconds
5 tests, 19 assertions, 5 failures, 0 skipped

THANK YOU

from frisby.

moses-gangipogu avatar moses-gangipogu commented on August 29, 2024

is there any thing in this line below

frisby.globalSetup({
request: {
/**
//adding this line to the code also give me an 406 HTTP error even in delete request
headers:{'Accept': 'application/json'}
},**/
timeout: (30 * 1000)
});

from frisby.

moses-gangipogu avatar moses-gangipogu commented on August 29, 2024

request: {
headers:{'Accept': 'application/json, application/x-httpd-php'}
},

its run perfect just by adding this line in the globalSetup
can u please explain why this problem came and how its solved??????????????

from frisby.

moses-gangipogu avatar moses-gangipogu commented on August 29, 2024

thank you and happy new year

from frisby.

moses-gangipogu avatar moses-gangipogu commented on August 29, 2024

OS = Ubuntu 12.04 LTS i am using .. is this because of this , i tried this same code in windows 7 it runs successfully in it without /**

headers:{'Accept': 'application/json, application/x-httpd-php'}

**/

this line
..but in Ubuntu 12.04 LTS .. its giving 406 error as given in my previous comment without this line's

..
thank you and sorry for my mistakes in English

from frisby.

vlucas avatar vlucas commented on August 29, 2024

HTTP 406 means the server can't accept or process the format that you're sending. Try sending the POST request without {json: true} so it gets transmitted as form-data:

frisby.create('testAddUser')
.post('http://root:123456@localhost/payCard/Api/User', {
    userName : 'newApi',
    Password : '123456',
    installationId : 1,
    cityId : 2,
})
.inspectJSON()
.inspectBody()
.toss()

from frisby.

moses-gangipogu avatar moses-gangipogu commented on August 29, 2024

thanks

from frisby.

mrded avatar mrded commented on August 29, 2024

Why { json: true } argument hasn't been mentioned in documentation?

from frisby.

maneeshrao66 avatar maneeshrao66 commented on August 29, 2024

Hello I am facing 500 error during delete request into frisby. The code is below please correct me if I have done any wrong..!

var frisby = require('frisby');

//get the current UTC time from this URL: (https://currentmillis.com/)
var now = new Date();
var now_utc = new Date(now.getUTCFullYear(), now.getUTCMonth(), now.getUTCDate(), now.getUTCHours(), now.getUTCMinutes(), now.getUTCSeconds())
var currentUTCTime = now_utc.getTime() - (now_utc.getTimezoneOffset() * 60000);

frisby.create('Authentication for Delete Request Valid User Name and Password')
  
     .delete('http://example.com',
      {
       headers:
        {
              'Accept':'application/json',
              'Auth-Username':'abcd',
              'X-Application-Key':'xyzzzz',
              'Content-Type':'application/json',
              'x-locale':'en_US',
              'x-microtime':currentUTCTime, //get the current UTC time
              'auth-signature': 'example', // Added new auth-signature for new responses
              }
           }   
        )
  .expectStatus(200)
  .toss()   

from frisby.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.