Passing a value to an ASPX page.
843790Jul 14 2010 — edited Aug 1 2010I'm trying to pass a value to an ASPX page from a java application. This is the code I'm using the pass the value:
----------------------------------------------------
// Construct data
String data = URLEncoder.encode("key1", "UTF-8") + "=" + URLEncoder.encode("hlaldfjl", "UTF-8");
// Send data
URL url = new URL("http:// ........ /test.aspx");
URLConnection conn = url.openConnection();
conn.setDoOutput(true);
OutputStreamWriter wr = new OutputStreamWriter(conn.getOutputStream());
wr.write(data);
wr.flush();
// Get the response
BufferedReader rd = new BufferedReader(new InputStreamReader(conn.getInputStream()));
StringBuffer answer = new StringBuffer();
String line;
while ((line = rd.readLine()) != null) {
// Process line...
answer.append(line);
}
wr.close();
rd.close();
System.out.println(answer.toString());
--------------------------------------------------------------------------------------
The ASPX page has the following:
fnameID=Request.QueryString("key1")
Response.Write("variable passed was " & fnameID)
-----------------------------------------------------------------------------------
When I run the Java code, I get:
variable passed was
BUILD SUCCESSFUL (total time: 1 second)
-----------------------------------------------------------------------------------
I guess that the connection to the URL is ok, but the variable "key1" is not being passed.
Any ideas? Any other easier ways to pass a variable through a POST method? I have done it before with ActionScript and it was really easy since they have a URLRequest and URLvariables methods; with Java I'm at lost...
Thanks in advance,