-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathinit.jsp
72 lines (63 loc) · 2.61 KB
/
init.jsp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
import java.io.*;
import java.net.*;
public class EncodingTest {
private static int startEncodingWorkflow() {
// replace ID and key with your own
String userID = "ID";
String userKey = "key";
String mediaID = "1";
StringBuffer xml = new StringBuffer();
xml.append("<?xml version=\"1.0\"?>");
xml.append("<query>");
xml.append("<userid>"+userID+"</userid>");
xml.append("<userkey>"+userKey+"</userkey>");
xml.append("<action>GetMediaInfo</action>");
xml.append("<mediaid>"+mediaID+"</mediaid>");
xml.append("</query>");
URL server = null;
try {
String url = "http://manage.encoding.com";
System.out.println("Connecting to:"+url);
server = new URL(url);
} catch (MalformedURLException mfu) {
mfu.printStackTrace();
return 0;
}
try {
String sRequest = "xml=" + URLEncoder.encode(xml.toString(), "UTF8");
System.out.println("Open new connection to tunnel");
HttpURLConnection urlConnection = (HttpURLConnection) server.openConnection();
urlConnection.setRequestMethod( "POST" );
urlConnection.setDoOutput(true);
urlConnection.setConnectTimeout(60000);
urlConnection.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
BufferedWriter out = new BufferedWriter( new OutputStreamWriter( urlConnection.getOutputStream() ) );
out.write(sRequest);
out.flush();
out.close();
urlConnection.connect();
InputStream is = urlConnection.getInputStream();
String str = urlConnection.getResponseMessage();
System.out.println("Response:"+urlConnection.getResponseCode());
System.out.println("Response:"+urlConnection.getResponseMessage());
StringBuffer strbuf = new StringBuffer();
byte[] buffer = new byte[1024 * 4];
try {
int n = 0;
while (-1 != (n = is.read(buffer))) {
strbuf.append(new String(buffer, 0, n));
}
is.close();
} catch (IOException ioe) {
ioe.printStackTrace();
}
System.out.println(strbuf.toString());
} catch (Exception exp) {
exp.printStackTrace();
}
return 0;
}
public static void main (String[] args) {
startEncodingWorkflow();
}
}