To download the quiz files containing questions and answers using web services follow the steps mentioned below.
1. You need below mentioned parameters before calling webservice function moodle_file_get_files.
a)contextid
b)component
c)filearea
d)itemid
e)filepath
f)filename
You will find values for above mentioned parameters from Moodle Table mdl_files.
SELECT * FROM moodle_apple.mdl_files;
2. Use the code to get information about the files.(below code helps to call the appropriate web service ,
you need add extra code for converting response in to a file)
package com.exilant.moodle;
import java.io.BufferedReader;
import java.io.DataOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.ProtocolException;
import java.net.URL;
import javax.xml.parsers.ParserConfigurationException;
import org.xml.sax.SAXException;
/**
*
* @author Mohan Kumar B M
*/
public class Moodle {
public static void main(String[] args) throws ProtocolException,
IOException, ParserConfigurationException, SAXException {
final String token = "";
final String domainName = "";
String functionName = "moodle_file_get_files";
String urlParameters = "contextid=153&component=user&filearea=draft&itemid=803619384&filepath=/&filename=Quiz.txt";
String serverurl = domainName + "/webservice/rest/server.php"
+ "?wstoken=" + token + "&wsfunction=" + functionName;
HttpURLConnection con = (HttpURLConnection) new URL(serverurl)
.openConnection();
con.setRequestMethod("POST");
con.setRequestProperty("Content-Type",
"application/x-www-form-urlencoded");
con.setRequestProperty("Content-Language", "en-US");
con.setDoOutput(true);
con.setUseCaches(false);
con.setDoInput(true);
DataOutputStream wr = new DataOutputStream(con.getOutputStream());
wr.writeBytes(urlParameters);
wr.flush();
wr.close();
// Get Response
InputStream is = con.getInputStream();
BufferedReader rd = new BufferedReader(new InputStreamReader(is));
String line;
StringBuilder response = new StringBuilder();
while ((line = rd.readLine()) != null) {
response.append(line);
response.append('\r');
}
rd.close();
System.out.println(response.toString());
}
}
**Sorry i didn't get time to complete code for downloading file.
For any queries please email me at mkbmbattu@gmail.com.
Thanks,
Mohan Kumar B M