llagerlof / MoodleRest

MoodleRest is a PHP class to query Moodle REST webservices
MIT License
86 stars 21 forks source link

Fix issue with POST parameters being separated by "&" instead of "&" #7

Open tgmayfield opened 1 year ago

tgmayfield commented 1 year ago

I battled for way too long to get the Moodle enrol_manual_enrol_users service to work. I finally got it working correctly with PHP curl functions, and then had to compare why that one worked and this code didn't. It came down to ampersands being in the POST data.

CURL post data:

enrolments%5B0%5D%5Broleid%5D=5&enrolments%5B0%5D%5Buserid%5D=8&enrolments%5B0%5D%5Bcourseid%5D=48&enrolments%5B0%5D%5Btimestart%5D=1693551600&enrolments%5B0%5D%5Btimeend%5D=1697353200

MoodleRest post data:

enrolments%5B0%5D%5Broleid%5D=5&enrolments%5B0%5D%5Buserid%5D=8&enrolments%5B0%5D%5Bcourseid%5D=48&enrolments%5B0%5D%5Btimestart%5D=1693548000&enrolments%5B0%5D%5Btimeend%5D=1697349600
llagerlof commented 1 year ago

@tgmayfield, thank you for taking the time to debug a potential problem with the library.

I find it strange because I use it to make GET and POST requests to more than one Moodle webservices in production systems and have never had an issue - works on my machineS ;-)

This makes me think that the error you're encountering is an exception. Based on your discovery, I'll try to reproduce this problem to determine if the solution you found works for all cases or if the root of the problem is something deeper.