动态网站制作指南 [  QQ表情  ]
[ 投票调查 ]
[ 企业邮箱 ]
[ 网站空间 ]
网络编程 | 站长之家 | 网页制作 | 图形图象 | 操作系统 | 冲浪宝典 | 软件教学 | 网络办公 | 邮件系统 | 网络安全 | 认证考试 | 系统进程
ASP源码 | .Net源码 | PHP源码 | JSP源码 | JAVA源码 | CGI源码 | VB源码 | C++源码 | Delphi源码 | PB源码 | VF源码 | 汇编 | 服务器
Firefox | IE | Maxthon | 迅雷 | 电驴 | BitComet | FlashGet | QQ | QQ空间 | Vista | 输入法 | Ghost | Word | Excel | wps | Powerpoint
asp | .net | php | jsp | Sql | c# | Ajax | xml | Dreamweaver | FrontPages | Javascript | css | photoshop | fireworks | Flash | Cad | Discuz!
当前位置 > 网站建设学院 > 网络编程 > Java教程
Tag:注入,存储过程,分页,安全,优化,xmlhttp,fso,jmail,application,session,防盗链,stream,无组件,组件,md5,乱码,缓存,加密,验证码,算法,cookies,ubb,正则表达式,水印,索引,日志,压缩,base64,url重写,上传,控件,Web.config,JDBC,函数,内存,PDF,迁移,结构,破解,编译,配置,进程,分词,IIS,Apache,Tomcat,phpmyadmin,Gzip,触发器,socket
网络编程:ASP教程,ASP.NET教程,PHP教程,JSP教程,C#教程,数据库,XML教程,Ajax,Java,Perl,Shell,VB教程,Delphi,C/C++教程,软件工程,J2EE/J2ME,移动开发
文章搜索服务
邮件订阅
输入你的邮件地址,
你将不会错过任何关于:
[ Java教程 ]的信息

本月文章推荐
.Java EJB容器的存取和实现.
.化繁为简 用Spring改进J2EE编程(.
.动态编译java程序实例.
.Java 3D 骰子动画代码范例.
.小TIP:Java里的时间比较.
.使用Ant进行Web开发, 第一部分.
.JAVA数据库基本操作指南.
.JDBC系列教程(五)---准备语句.
.J2EE编程起步.
.Java咖啡馆(4)——品味第一杯咖啡.
.The Model-View-Controller Arch.
.专稿:实战EJB之五 开发实体BMP(.
.Lucene --open source text serc.
.Javascript实例教程(19) 使用HoT.
.Java应用者与IDE 环境.
.enoeht的Java源码系列之处理配置.
.FreeJava 的使用方法.
.java笔记.
.我找到一个最简单的hibernate入门.
.将J2EE平台提升到一个新的高度.

Acme包中的以Post方式发送数据的例子

发表日期:2008-1-5 |



  作者:sonymusic
email: sonymusic@china.com
日期:2001-5-11 13:55:13
package Acme;

import Java.net.*;
import java.io.*;
import java.util.*;
import java.text.*;

/// A URLConnection that implements POST.
// <P>
// Some implementations of URLConnection, e.g. the one in Navigator 3.0,
// do not support POST. This is a stripped-down version that does.
// <P>
// Note that it can´t inherit from java.net.URLConnection because that
// class has no public constrUCtors. Not all the standard URLConnection
// methods are re-implemented here, just the ones necessary for posting.
// <P>
// This class is not needed in current browsers.
// <P>
// <A HREF="/resources/classes/Acme/PostURLConnection.java">Fetch the software.</A><BR>
// <A HREF="/resources/classes/Acme.tar.gz">Fetch the entire Acme package.</A>

public class PostURLConnection
{

private URL url;
private boolean doInput = false;
private boolean doOutput = true;
private boolean useCaches = false;

private Vector reqHeaderNames = new Vector();
private Vector reqHeaderValues = new Vector();
private Vector resHeaderNames = null;
private Vector resHeaderValues = null;
private Socket socket;
private OutputStream out;
private InputStream in;


/// Constructs a POST URL connection to the specified URL.
// @param url the specified URL
public PostURLConnection( URL url )
{
this.url = url;
}


private boolean connected = false;

public void connect() throws IOException
{
if ( connected )
return;
if ( ! useCaches )
setRequestProperty( "Pragma", "no-cache" );
String protocol = url.getProtocol();
if ( ! protocol.equals( "http" ) )
throw new UnknownServiceException( "unknown protocol" );
String host = url.getHost();
int port = url.getPort();
if ( port == -1 )
port = 80;
String file = url.getFile();
socket = new Socket( host, port );
out = socket.getOutputStream();
PrintStream pout = new PrintStream( out );
String method;
if ( doOutput )
method = "POST";
else
method = "GET";
pout.println( method + " " + file + " HTTP/1.0" );
for ( int i = 0; i < reqHeaderNames.size(); ++i )
{
String name = (String) reqHeaderNames.elementAt( i );
String value = (String) reqHeaderValues.elementAt( i );
pout.println( name + ": " + value );
}
pout.println( "" );
pout.flush();
connected = true;
}


private boolean inputStarted = false;

private void startInput() throws IOException
{
connect();
if ( inputStarted )
return;
in = socket.getInputStream();
resHeaderNames = new Vector();
resHeaderValues = new Vector();
DataInputStream din = new DataInputStream( in );
String line;
// Read and ignore the status line.
line = din.readLine();
// Read and save the header lines.
while ( true )
{
line = din.readLine();
if ( line == null line.length() == 0 )
break;
int colonBlank = line.indexOf( ": " );
if ( colonBlank != -1 )
{
String name = line.substring( 0, colonBlank );
String value = line.substring( colonBlank + 2 );
resHeaderNames.addElement( name.toLowerCase() );
resHeaderValues.addElement( value );
}
}
inputStarted = true;
}


public void close() throws IOException
{
if ( ! connected )
return;
out.close();
if ( inputStarted )
in.close();
socket.close();
}


/// Gets the URL for this connection.
public URL getURL()
{
return url;
}

// Gets the content length. Returns -1 if not known.
public int getContentLength() throws IOException
{
return getHeaderFieldInt( "content-length", -1 );
}

/// Gets the content type. Returns null if not known.
public String getContentType() throws IOException
{
return getHeaderField( "content-type" );
}

/// Gets a header field by name. Returns null if not known.
// @param name the name of the header field
public String getHeaderField( String name ) throws IOException
{
if ( resHeaderNames == null )
startInput();
int i = resHeaderNames.indexOf( name.toLowerCase() );
if ( i == -1 )
return null;
return (String) resHeaderValues.elementAt( i );
}

/// Gets a header field by name. Returns null if not known.
// The field is parsed as an integer.
// @param name the name of the header field
// @param def the value to return if the field is missing or malformed.
public int getHeaderFieldInt( String name, int def ) throws IOException
{
try
{
return Integer.parseInt( getHeaderField( name ) );
}
catch ( NumberFormatException t )
{
return def;
}
}


/// Gets a header field by name. Returns null if not known.
// The field is parsed as a date.
// @param name the name of the header field
// @param def the value to return if the field is missing or malformed.
public long getHeaderFieldDate( String name, long def ) throws IOException
{
try
{
return DateFormat.getDateInstance().parse( getHeaderField( name ) ).getTime();
}
catch ( ParseException e )
{
throw new IOException( e.toString() );
}
}

/// Call this routine to get an InputStream that reads from the object.
// @exception UnknownServiceException If the protocol does not support input.
public InputStream getInputStream() throws IOException
{
if ( ! doInput )
throw new UnknownServiceException(
"connection doesn´t support input" );
startInput();
return in;
}

/// Call this routine to get an OutputStream that writes to the object.
// @exception UnknownServiceException If the protocol does not support output.
public OutputStream getOutputStream() throws IOException
{
if ( ! doOutput )
throw new UnknownServiceException(
"connection doesn´t support output" );
connect();
return out;
}


/// Returns the String representation of the URL connection.
public String toString()
{
return this.getClass().getName() + ":" + url;
}


/// A URL connection can be used for input and/or output. Set the DoInput
// flag to true if you intend to use the URL connection for input,
// false if not. The default for PostURLConnections is false.
public void setDoInput( boolean doInput )
{
if ( connected )
throw new IllegalAccessError( "already connected" );
this.doInput = doInput;
}

public boolean getDoInput()
{
return doInput;
}


/// A URL connection can be used for input and/or output. Set the DoOutput
// flag to true if you intend to use the URL connection for output,
// false if not. The default for PostURLConnections is true.
public void setDoOutput( boolean doOutput )
{
if ( connected )
throw new IllegalAccessError( "already connected" );
this.doOutput = doOutput;
}

public boolean getDoOutput()
{
return doOutput;
}


/// Some protocols do caching of documents. Occasionally, it is important
// to be able to "tunnel through" and ignore the caches (e.g. the "reload"
// button in a browser). If the UseCaches flag on a connection is true,
// the connection is allowed to use whatever caches it can. If false,
// caches are to be ignored. The default for PostURLConnections is false.
public void setUseCaches( boolean useCaches )
{
if ( connected )
throw new IllegalAccessError( "already connected" );
this.useCaches = useCaches;
}

public boolean getUseCaches()
{
return useCaches;
}


// Sets/gets a general request property.
// @param name The keyWord by which the request is known (eg "accept")
// @param value The value associated with it.
public void setRequestProperty( String name, String value )
{
if ( connected )
throw new IllegalAccessError("already connected");
reqHeaderNames.addElement( name );
reqHeaderValues.addElement( value );
}

public String getRequestProperty( String name )
{
if ( connected )
throw new IllegalAccessError( "already connected" );
int i = reqHeaderNames.indexOf( name );
if ( i == -1 )
return null;
return (String) reqHeaderValues.elementAt( i );
}

}
上一篇:iPlanet 6.0综合介绍 人气:743
下一篇:a Socket编程中的一个秘密类 人气:445
浏览全部Java的内容 Dreamweaver插件下载 常用网页广告代码全集
  最新网站源码 最新软件下载
2008-10-13 爬爬思特新闻管理系统 v2.0 Beta1
2008-10-13 Pligg v9.9.5 Beta
2008-10-13 广优邮件发送系统 v2.1
2008-10-13 缤纷互动视频交友 v3.1 RC
2008-10-13 MyShop网络商城 build 081005
2008-10-13 Chyrp 超轻量级开源博客引擎 v2.
2008-10-13 162100静态(论坛/文章)系统 v2.4
2008-10-13 金博人才招聘求职网黄金版 v4.2
2008-10-13 愚人笔记 v4.0
2008-10-11 联系人分组工具 v1.1 中文破解版
2008-10-11 FaceMelter变脸 v2.0 汉化破解版
2008-10-11 PathTracker道路跟踪仪 v1.2 破解
2008-10-11 Rooms手机聊天室 v0.6.7 破解版
2008-10-11 RemoteDesktop远程桌面 v1.0 破解
2008-10-11 ProRemote远程调音台 v1.0.1 破解
2008-10-11 PicShare照片共享 v1.0.0 破解版
2008-10-11 Photogene照片编辑器 v1.5 汉化破
2008-10-11 WriteRoom共享文档 v1.0 破解版
  发表评论
姓 名: 验证码:
内 容:
站长工具:网站收录查询 | Google PR查询 | ALEXA排名查询 | CSS在线编辑器 | 广告代码 | js/vbs加密 | md5加密 | 进制转换 | UTF-8 转换工具 | Html转换js | Html转换asp | Html转换php | Html转换perl
实用工具:汉字翻译拼音 | 拼音字典 | 符号对照表 | 个税计算 | 实时汇率查询换算 | 经典小工具 | 汉字简繁转换 | 普通单位换算 | 公制单位换算 | 生辰老黄历 | 国内电话区号 | 国家代码与域名缩写 | 文字加密解密 | 健康查询 | 万年历 | 汉字横竖排版 | 手机号码查询 | 计算器 | ip搜索
业务联系 | 广告刊登 | 频道合作 | 投稿荐稿 | 联系方式 | 加入收藏 | RSS订阅
Copyright © 2000-2008 www.knowsky.com All rights reserved | 网络实名:动态网站制作指南 | 沪ICP备05001343号
ホームページ制作 不動産検索システム 求人情報
防水工事·改修工事 フットサル大会 探偵
SEO対策 中国語教室 ホームページ作成