EasyManua.ls Logo

Mitsubishi Electric QJ71MES96N - Sample Program

Mitsubishi Electric QJ71MES96N
484 pages
To Next Page IconTo Next Page
To Next Page IconTo Next Page
To Previous Page IconTo Previous Page
To Previous Page IconTo Previous Page
Loading...
9 - 5
9.2 XML Message Format Sending Method
9.2.2 Sample program
9
XML MESSAGE FORMAT
9.2.2 Sample program
This section shows a sample program written in Java.
import java.io.*;
import java.net.*;
class JobStart {
public static void main(String[] args) {
try{
// Storage of request message
String requestMessage = "<?xml version=\"1.0\"?>";
requestMessage += "<REQUEST type=\"oneshot\" jobname=\"Pro01\"/>";
System.err.println(requestMessage );// Send contents display
// Conversion with URL encording
requestMessage = URLEncoder.encode(requestMessage, "UTF-8");
// POST
URL url = new URL("http://192.168.3.3/MESXML.cgi");
URLConnection conn = url.openConnection();
conn.setDoOutput(true);
conn.setUseCaches(false);
conn.setRequestProperty("Content-type", "text/xml");
conn.setRequestProperty("Content-length", String.valueOf(requestMessage.length()));
// BASIC authentication
String account = "QJ71MES96:MITSUBISHI";
String enc_account = new String(encodeBase64(account));
conn.setRequepstProperty("Authorization", "Basic " + enc_account);
OutputStream outStream = conn.getOutputStream();
PrintStream printStream = new PrintStream(outStream);
printStream.print(requestMessage);
printStream.close();
InputStream inputStream = conn.getInputStream();
BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream));
String STr;
while ((str = reader.readLine()) != null){
System.out.println(str);// Receive contents display
}
reader.close();
}catch(Exception e){
System.err.println("Errorn\n" + e);
}
}
(To the next page)

Table of Contents

Related product manuals