01: /*
02: * CONFIDENTIAL AND PROPRIETARY SOURCE CODE OF
03: * NETSCAPE COMMUNICATIONS CORPORATION
04: *
05: * Copyright (c) 1996 Netscape Communications Corporation.
06: * All Rights Reserved.
07: * Use of this Source Code is subject to the terms of the applicable
08: * license agreement from Netscape Communications Corporation.
09: */
10:
11: package communications;
12:
13: import java.applet.Applet;
14:
15: /**
16: A wee bitty applet to allow JavaScript to do GET and POST.
17: No brain cells were harmed in the creation of this code.
18: *
19: */
20: public class Connection extends Applet {
21: /**
22: * Do the GET thing.
23: * @param target target for the GET
24: */
25: public String get(String target) {
26: String s = null;
27:
28: ReadConnection readConnection = new ReadConnection(target);
29:
30: if (readConnection.openIn() == false) {
31: return null;
32: }
33:
34: s = readConnection.doRead();
35:
36: if (readConnection.closeIn() == false) {
37: return null;
38: }
39:
40: return s;
41: }
42:
43: /**
44: * Do the POST thing.
45: * @param target target for the POST
46: * @param request request for the POST
47: */
48: public String post(String target, String request) {
49: String s = null;
50:
51: PostConnection postConnection = new PostConnection(target);
52:
53: if (postConnection.openOut() == false) {
54: return null;
55: }
56:
57: postConnection.writeBytes(request);
58:
59: if (postConnection.closeOut() == false) {
60: return null;
61: }
62:
63: if (postConnection.openIn() == false) {
64: return null;
65: }
66:
67: s = postConnection.doRead();
68:
69: if (postConnection.closeIn() == false) {
70: return null;
71: }
72:
73: return s;
74: }
75: }
|