-
Notifications
You must be signed in to change notification settings - Fork 9.3k
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
Fix CURL Json POST #3489 #8373
Fix CURL Json POST #3489 #8373
Conversation
* @return void | ||
* @SuppressWarnings(PHPMD.CyclomaticComplexity) | ||
* @SuppressWarnings(PHPMD.NPathComplexity) | ||
*/ | ||
protected function makeRequest($method, $uri, $params = []) | ||
protected function makeRequest($method, $uri, $params = [], $json = false) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for your contribution to Magento 2 project.
Adding this logic to protected method requires extension developers inherit this class. This is what we are trying to avoid in Magento 2.
Could you please provide more details about your use case? Maybe we will suggest a better way how we can achieve your goal
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@okorshenko how should we do get/post requests?
In our case we need to send post with json.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I got your point, we need to modify post, get method too. Not just this protected method.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for the fixes. Unfortunately, by this fix you modified public interface of the class and added knowledge about JSON for Curl client. On the other hand, how to post XML request for instance? We don't want to add $isXML flag to the method again. So we need to have something more general - string format.
Let me suggest another approach:
* @param array|string $params
protected function makeReques (...) {
...
$this->curlOption(CURLOPT_POSTFIELDS, is_array($params) ? http_build_query($params) : $params);
...
}
We are extending our contract by adding new supported type string wihtout changes in public method parameters.
Please, do not forget to align makeRequest and post method signatures.
Thank you for reporting and fixing this issue. Good catch! +100500 to your karma! ;)
@okorshenko pull request is updated. |
* @return void | ||
* @SuppressWarnings(PHPMD.CyclomaticComplexity) | ||
* @SuppressWarnings(PHPMD.NPathComplexity) | ||
*/ | ||
protected function makeRequest($method, $uri, $params = []) | ||
protected function makeRequest($method, $uri, $params = [], $json = false) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for the fixes. Unfortunately, by this fix you modified public interface of the class and added knowledge about JSON for Curl client. On the other hand, how to post XML request for instance? We don't want to add $isXML flag to the method again. So we need to have something more general - string format.
Let me suggest another approach:
* @param array|string $params
protected function makeReques (...) {
...
$this->curlOption(CURLOPT_POSTFIELDS, is_array($params) ? http_build_query($params) : $params);
...
}
We are extending our contract by adding new supported type string wihtout changes in public method parameters.
Please, do not forget to align makeRequest and post method signatures.
Thank you for reporting and fixing this issue. Good catch! +100500 to your karma! ;)
@okorshenko good point, I've updated pull request |
@Grohotun thank you for contribution! We accepted your initial code with some small fixes. Thank you! |
Add ability to make json requests
Issue #3489