You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm working on a project that requires sending POST requests with 'application/x-www-form-urlencoded' encoding, specifically handling multiple values for a singular key (e.g., 'scope'). This is a common pattern in OAuth2 authorization and other API interactions, where you need to, for example, define authorization grant types.
Currently, I can achieve this with Fetch in JavaScript, but I'm unable to find a way to replicate this behavior using Playwright's APIRequestContext class.
let requestHeaders = new Headers();
requestHeaders.append("Content-Type", "application/x-www-form-urlencoded");
let urlEncoded = new URLSearchParams();
urlEncoded.append("scope", "value1");
urlEncoded.append("scope", "value2");
urlencoded.append("scope", "value3");
urlencoded.append("scope", "value4");
// and so on
let requestOptions = {
method: 'POST',
headers: requestHeaders,
body: urlEncoded,
redirect: 'no-follow'
};
fetch("https://example.com/authorize", requestOptions)
.then(response => response.text())
.then(result => console.log(result))
.catch(error => console.log('error', error));
However, I'm struggling to find a way to replicate this behavior using the APIRequestContext class in Playwright. Here's what I've tried so far:
await apiRequestContext.post('https://example.com/authorize', {
headers: { "Content-Type": "application/x-www-form-urlencoded" },
form: {
"response_type": "auth_code",
"scope": "value1", // How to handle multiple values for 'scope'?
// rest of the parameters
}
});
Since currently there's no way to handle multiple values for a singular key like 'key' using the APIRequestContext, I think it would be beneficial to be able to provide multiple values for one key, in a similar fashion it is achieved by URLSearchParams. It could be, for example, passed in an array of strings.
The text was updated successfully, but these errors were encountered:
szuszik
changed the title
[Feature] Ability to handle multiple values for a singular key in .fetch() with APIRequestContext
[Feature] Ability to handle multiple values for a singular key in .fetch() with APIRequestContext
Aug 17, 2023
I'm working on a project that requires sending POST requests with 'application/x-www-form-urlencoded' encoding, specifically handling multiple values for a singular key (e.g., 'scope'). This is a common pattern in OAuth2 authorization and other API interactions, where you need to, for example, define authorization grant types.
Currently, I can achieve this with Fetch in JavaScript, but I'm unable to find a way to replicate this behavior using Playwright's APIRequestContext class.
However, I'm struggling to find a way to replicate this behavior using the APIRequestContext class in Playwright. Here's what I've tried so far:
Since currently there's no way to handle multiple values for a singular key like 'key' using the APIRequestContext, I think it would be beneficial to be able to provide multiple values for one key, in a similar fashion it is achieved by URLSearchParams. It could be, for example, passed in an array of strings.
The text was updated successfully, but these errors were encountered: