URL 发送post请求

04-11-25 dealover

dealover
2004-11-25 16:22

public static void send(){
		java.net.URL url = null;
				java.net.URLConnection conn = null;
				java.io.InputStream in = null;
				java.io.ByteArrayOutputStream bStream = null;
		  try {
				   url = new URL("http://172.16.0.28/app/SysServlet?");
					 conn = (HttpURLConnection) url.openConnection();
					 conn.setDoOutput(true);
					 DataOutputStream Out=new DataOutputStream(conn.getOutputStream());
					 Out.write("message".getBytes());
				java.io.InputStream  is = conn.getInputStream();
					 is.close();
					 Out.flush();
					 Out.close();
			} catch (MalformedURLException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			} catch (IOException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		
	}

dealover
2004-11-25 16:25
我用send方法发送一个get或者post请求,请求可以到达图里边的servlet类,但是并不能执行onload和input中的转向操作,如果我不用java类中的URL做请求直接在浏览器中输入地址是可以成功执行的.

猜你喜欢