Post answers directly in URL

This discussion has been locked because a year has elapsed since the last post. Please start a new discussion topic.
Tim at Lone Pine Koala Sanctuary
Re: Post answers directly in URL
Group Core developersGroup Documentation writersGroup Particularly helpful MoodlersGroup Plugin developers

The error is just confusing, the key thing is the 303 response code. That is a redirect. Where is the redirect going? It does not say, but I bet you are being redirected to .../login/index.php. (Line 86 of processattemp.php.)

So, in order to make the POST request work, you need to find a way to establish a Moodle session for the user on whose behalf you are submittin answers.

Now, as I said, the transaction error is not relevant, but just to explain it. We start a transaction on line 48 of processattemp.php, before the call to require login. Now, either that is a bug in my code, if you are not supposed to do that; or it is a bug in require_login() or redirec(), if they are incorrectly assuming that a transaction has not been started.

I will have to ask some other Moodle developers which bit of code needs to be fixed there.

Average of ratings: -
I Teach With Moodle
Re: Post answers directly in URL
Group Plugin developersGroup Testers

thanks again for your answer. The redirect is indeed to the login page. Here are the logs for the test_post.php file

[04/Dec/2012:08:26:34 +0000] "POST /moodle/mod/quiz/processattempt.php? HTTP/1.1" 303 1068 "-" "-"
[04/Dec/2012:08:26:34 +0000] "GET /moodle/login/index.php HTTP/1.1" 200 12153 "-" "-"
[04/Dec/2012:08:26:34 +0000] "GET /moodle/mod/quiz/test_post.php HTTP/1.0" 200 440 "-"

This test_post.php is called in a 'browser' that already has a Moodle session running (I am puzzled it takes me to the login page), so I have added a bit of code to catch the session key and parse it into the URL, here is the amended code; 

require_once(dirname(__FILE__) . '/../../config.php');
require_once($CFG->dirroot . '/mod/quiz/locallib.php');

$myvar1= '333';

$myvar2= '0';

$myvar3= '352';

$myvar4= '5589';
$myvar5= $USER->sesskey;

$url = 'http://www.somemoodle.com/moodle/mod/quiz/processattempt.php?';
$myvars = 'attempt=' . $myvar1 . '&page=' . $myvar2 .'&questionids=' . $myvar3 .'&answer=' . $myvar4 .'&sesskey=' . $myvar5;

$ch = curl_init($url);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $myvars);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);

$response = curl_exec( $ch );
curl_close ($ch);

I still get the same errors. Am I correct to think that the same sort of URL is posted when using JMeter? Could it be a problem with the way I use cURL?


Average of ratings: -