🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: borland.public.jbuilder.java.api
Article #47

Re: Cannot pass parameters using GET method when using URLConnection in java.net

#47
From: Michael Clark
Date: Thu, 17 Feb 2005 06:22
58 lines
2877 bytes
Try this:

URL url = new URL("http://confserver:8500/index.cfm?SMS_MsgTxt=Jonathan");
URLConnection conn = url.connect();
conn.getInputStream().close();


"Jonathan Estabillo" <nathanestabillo@netscape.net> wrote in message 
news:41ae84eb$1@newsgroups.borland.com...
> Hi there everyone. I am finding a hard time sending URL parameters using 
> the java.net package. I can connect to the specific URL but it seems that 
> the parameters are not being passed. How do I go about it? By the way here 
> is the code for a simple application to pass URL parameters using the GET 
> method but in reality it does not pass the parameters:
>
>
> HERE IS THE CODE THAT I'M TRYING TO WORK ON
> ***************************************************************************
> package testing;
>
> import javax.servlet.*;
> import javax.servlet.http.*;
> import java.io.*;
> import java.net.*;
>
> public class Servlet1 extends HttpServlet {
>
>     //Initialize global variables
>     public void init() throws ServletException {
>     }
>
>     public void doGet(HttpServletRequest request, HttpServletResponse 
> response) throws
>             ServletException, IOException {
>         try {
>             URL url = new URL(
>                     "http://confserver:8500/index.cfm?");
>             URLConnection conn = url.openConnection();
>             conn.setDoOutput(true);
>             OutputStreamWriter wr = new 
> OutputStreamWriter(conn.getOutputStream());
>             wr.write("SMS_MsgTxt=Jonathan");
>             wr.close();
>         } catch (Exception ex) {
>             ex.printStackTrace();
>         }
>     }
>
>     public void doPost(HttpServletRequest request, HttpServletResponse 
> response) throws
>             ServletException, IOException {
>         doGet(request, response);
>     }
>
>     //Clean up resources
>     public void destroy() {
>     }
> } 
Technical Details
Message-ID: <42143826$1@newsgroups.borland.com>
Path: arc1-ca.pugleaf.net!g2news1.google.com!news1.google.com!proxad.net!fr.ip.ndsoftware.net!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail
References: <41ae84eb$1@newsgroups.borland.com>

Show Full Headers
Complete Article Headers
X-Google-Thread: 1089d0,a6b579cb5bacaf3b
X-Google-Attributes: gid1089d0,public
X-Google-Language: ENGLISH,ASCII-7-bit
From: "Michael Clark" <no-spam@email.invalid>
Newsgroups: borland.public.jbuilder.java.api
References: <41ae84eb$1@newsgroups.borland.com>
Subject: Re: Cannot pass parameters using GET method when using URLConnection in java.net
Date: Wed, 16 Feb 2005 23:22:33 -0700
Lines: 60
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.2900.2180
X-RFC2646: Format=Flowed; Response
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.2180
NNTP-Posting-Host: 24.9.62.114
Message-ID: <42143826$1@newsgroups.borland.com>
X-Trace: newsgroups.borland.com 1108621350 24.9.62.114 (16 Feb 2005 22:22:30 -0800)
Path: arc1-ca.pugleaf.net!g2news1.google.com!news1.google.com!proxad.net!fr.ip.ndsoftware.net!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail