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

sendPOST and urlencoded data #1914

Closed
bmtKIA6 opened this issue May 10, 2015 · 10 comments
Closed

sendPOST and urlencoded data #1914

bmtKIA6 opened this issue May 10, 2015 · 10 comments

Comments

@bmtKIA6
Copy link

bmtKIA6 commented May 10, 2015

It seems that I am unable to execute a POST with the form-urlencoded data, and my parameters
are always converted to json regardless of the content-type header

    $data = [
        'client_id' => OAuthTestSeeder::CLIENT_ID,
        'client_secret' => OAuthTestSeeder::CLIENT_SECRET,
        'grant_type'    => 'password',
        'username'      => OAuthTestSeeder::USER_EMAIL,
        'password'      => OAuthTestSeeder::USER_PASSWORD
    ];

    $I->wantTo('Try to obtain access token w credentials');
    $I->haveHttpHeader('Content-Type','application/x-www-form-urlencoded');
    $I->sendPOST('oauth2/access_token', $data);
  • I have http header "Content-Type","application/x-www-form-urlencoded"

  • I send post "oauth2/access_token",{"client_id":"test-client-id","client_secret":"test-client-secret","grant_type":"password","username":"pdpp@dssdpdpd.com","password":"pdpassword"}

    [Request headers] {"Content-Type":"application/x-www-form-urlencoded"}
    [Request] POST /v1/oauth2/access_token {"client_id":"test-client-id","client_secret":"test-client-secret","grant_type":"password","username":"pdpp@dssdpdpd.com","password":"pdpassword"}

and w/o the headers

[Request headers] []
[Request] POST /v1/oauth2/access_token {"client_id":"test-client-id","client_secret":"test-client-secret","grant_type":"password","username":"pdpp@dssdpdpd.com","password":"pdpassword"}

./vendor/bin/codecept -V
Codeception version 2.0.13

@DavertMik DavertMik added the REST label May 10, 2015
@reksc
Copy link

reksc commented May 12, 2015

Parameters are always converted to json when passed to debug log.

See Codeception/Module/REST.php, lines 384:389

if($method == 'GET') {
    $this->debugSection("Request", "$method $url");
} else {
    $this->debugSection("Request", "$method $url ".json_encode($parameters));
}

@Naktibalda
Copy link
Member

Not a bug.

@shivavuppala
Copy link

Hi @Naktibalda is there a work around for this ? How can we send non json format as part of post request (x-www-form-urlencoded) ?

@Naktibalda
Copy link
Member

@shivavuppala You want a workaround for non-bug, it was an issue of visual representation.

Don't set content-type header to application/json.

@shivavuppala
Copy link

@Naktibalda my request has a header of content type as (application/x-www-form-urlencoded).

@shivavuppala
Copy link

@Naktibalda Below is the Request and Response
Request:
et auth = await I.sendPostRequest('https:/XXX/oktaauth/token',
{'grant_type': "password",
redirect_uri: "http://localhost:4200/implicit/callback",
username: "123@test.com.au",
password: “Password@1”,
scope: "openid"},
{
Authorization: "Basic",
"Content-Type": "application/x-www-form-urlencoded",
"Ocp-Apim-Subscription-Key": "d40dd258808b449ba1b61f4baf510d4e"
});

console.log("Auth = " + auth.data.access_token);

Response:
[Response] Response error. Status code: 400
› [Response] {"error":"invalid_request","error_description":"The token request must specify a 'grant_type'. Valid values: [authorization_code, password, refresh_token]"}

@shivavuppala
Copy link

Where as it works fine with additional parameter type when tried using mocha
Mocha Request:
api.post('/oktaauth/token')
.set('Authorization', 'Basic')
.set('Ocp-Apim-Subscription-Key', subscriptionKey)
.type('form') --- The additional parameter

@Naktibalda
Copy link
Member

What has your code got to do with Codeception?

@shivavuppala
Copy link

Am getting error on codeceptjs for 'sendPostRequest'. Is it different from codeception?

@Naktibalda
Copy link
Member

CodeceptJS is a different project.

https://github.com/Codeception/CodeceptJS

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

5 participants