Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > posting to cgi from applet

Reply
Thread Tools

posting to cgi from applet

 
 
Miguel De Anda
Guest
Posts: n/a
 
      09-02-2003
What is the normal/standard way to post data from an applet to the web
server? We don't want to open another port on the server and instead do it
from port 80. I was thinking that I can base64 encode the data, and put it
in a querystring like this:
http://www.mywebsite.com/myappletpos...wijfoweijfowei.....

Would this work well? I can't think of another way. What's the max length
that a url can have?


 
Reply With Quote
 
 
 
 
Ike
Guest
Posts: n/a
 
      09-03-2003
Not sure I understand...perhaps this helps - Ike


/**
*executes a Post request to the server, for calling CGI scripts
essentially
*@param theCGI the URL pointing to the CGI script to exectue
*@param param[] an array of parameter names to pass to the script
*param value[] an array of parameter values, corresponding to the array
of parameter names
*/
protected void doCGI_POST(String theCGI, String param[], String
value[]){
/*
The POST method allows the programmer to manipulate the data
received from the CGI.
First a connection is made to the CGI, an OutputStream is open to
send the parameters (if any).
Then InputStream is created to receive the result.
*/
URL CGIurl=null;
URLConnection c=null;
DataOutputStream out=null;
try{
CGIurl = new URL(theCGI);
c = CGIurl.openConnection();
c.setDoOutput(true);
c.setUseCaches(false);

c.setRequestProperty("content-type","application/x-www-form-urlencoded");
out = new DataOutputStream(c.getOutputStream());

StringBuffer encoded = new StringBuffer(1000);
for(int x=0;x<param.length;x++){
encoded.append(param[x]);
encoded.append("=");
encoded.append(URLEncoder.encode(value[x]));
if(x<param.length-1)
encoded.append("&");
}

out.writeBytes(encoded.toString());
out.flush(); out.close();

BufferedReader in = new BufferedReader(new
InputStreamReader(c.getInputStream()));
String aLine;
while ((aLine = in.readLine()) != null) {
// data from the CGI
System.out.println(aLine);
}
}catch(Exception e){
System.out.println("Problem with CGI request! "+e);
e.printStackTrace();
}
}

you call this method, for example, as follows:

String p[] ={
"recipient",
"subject",
"env_report",
"realname",
"email",
"comments"
};

String v[]= {
RFQTo,
"Request For Quote",
"HTTP_USER_AGENT,REMOTE_HOST,REMOTE_ADDR,HTTP_X_FO RWARDED_FOR",
realName,
emailFrom,
"blah blah blah:\n\n" + msg
};

doCGI_POST("http://www.selectthat.com/cgi-bin/FormMail.pl", p, v);
//-Ike

"Miguel De Anda" <_sodamnmad_@_hotmail_._com_> wrote in message
news: s.com...
> What is the normal/standard way to post data from an applet to the web
> server? We don't want to open another port on the server and instead do it
> from port 80. I was thinking that I can base64 encode the data, and put it
> in a querystring like this:
>

http://www.mywebsite.com/myappletpos...wijfoweijfowei.....
>
> Would this work well? I can't think of another way. What's the max length
> that a url can have?
>
>



 
Reply With Quote
 
 
 
 
Miguel De Anda
Guest
Posts: n/a
 
      09-03-2003
Aahhh... that looks like what I need. I'll take a good look at the
URLConnection/HttpURLConnection objects. I take it that it can do it like a
regular form post. That seems best.




"Ike" <> wrote in message
newsCb5b.17087$ link.net...
> Not sure I understand...perhaps this helps - Ike
>
>
> /**
> *executes a Post request to the server, for calling CGI scripts
> essentially
> *@param theCGI the URL pointing to the CGI script to exectue
> *@param param[] an array of parameter names to pass to the script
> *param value[] an array of parameter values, corresponding to the

array
> of parameter names
> */
> protected void doCGI_POST(String theCGI, String param[], String
> value[]){
> /*
> The POST method allows the programmer to manipulate the data
> received from the CGI.
> First a connection is made to the CGI, an OutputStream is open to
> send the parameters (if any).
> Then InputStream is created to receive the result.
> */
> URL CGIurl=null;
> URLConnection c=null;
> DataOutputStream out=null;
> try{
> CGIurl = new URL(theCGI);
> c = CGIurl.openConnection();
> c.setDoOutput(true);
> c.setUseCaches(false);
>
> c.setRequestProperty("content-type","application/x-www-form-urlencoded");
> out = new DataOutputStream(c.getOutputStream());
>
> StringBuffer encoded = new StringBuffer(1000);
> for(int x=0;x<param.length;x++){
> encoded.append(param[x]);
> encoded.append("=");
> encoded.append(URLEncoder.encode(value[x]));
> if(x<param.length-1)
> encoded.append("&");
> }
>
> out.writeBytes(encoded.toString());
> out.flush(); out.close();
>
> BufferedReader in = new BufferedReader(new
> InputStreamReader(c.getInputStream()));
> String aLine;
> while ((aLine = in.readLine()) != null) {
> // data from the CGI
> System.out.println(aLine);
> }
> }catch(Exception e){
> System.out.println("Problem with CGI request! "+e);
> e.printStackTrace();
> }
> }
>
> you call this method, for example, as follows:
>
> String p[] ={
> "recipient",
> "subject",
> "env_report",
> "realname",
> "email",
> "comments"
> };
>
> String v[]= {
> RFQTo,
> "Request For Quote",
>

"HTTP_USER_AGENT,REMOTE_HOST,REMOTE_ADDR,HTTP_X_FO RWARDED_FOR",
> realName,
> emailFrom,
> "blah blah blah:\n\n" + msg
> };
>
> doCGI_POST("http://www.selectthat.com/cgi-bin/FormMail.pl", p, v);
> //-Ike
>
> "Miguel De Anda" <_sodamnmad_@_hotmail_._com_> wrote in message
> news: s.com...
> > What is the normal/standard way to post data from an applet to the web
> > server? We don't want to open another port on the server and instead do

it
> > from port 80. I was thinking that I can base64 encode the data, and put

it
> > in a querystring like this:
> >

>

http://www.mywebsite.com/myappletpos...wijfoweijfowei.....
> >
> > Would this work well? I can't think of another way. What's the max

length
> > that a url can have?
> >
> >

>
>



 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
URL Posting Fails in Medium Trust (3rd time posting this w/ zero replies so far) AmitKu ASP .Net 7 01-08-2007 07:31 PM
CROSS-POSTING, OR MULTI-POSTING, OR NEITHER? Colin D Digital Photography 56 03-08-2006 08:31 PM
[OT] : Top Posting vs Bottom Posting Wayne Wastier Windows 64bit 7 07-17-2005 03:57 PM
Top Posting vs. Bottom Posting scaredkitty Computer Support 37 04-06-2005 12:27 AM
Everytime I hover cursro over a posting, it crosses out with red mark on it.. on every posting alanb ASP .Net 2 04-23-2004 02:23 PM



Advertisments
 



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