String urlstring="http://member.ecplaza.net/auth.do?MemberID=tradediscovery1&Password=123456&action=login&rurl=http://www.ecplaza.net/InquiryBox/InquiryBox.do?subject=new year&comments=tttttttttttttttttttttttt&mode=RFQ&id=1894977&clickfrom=M&cmd=send&ConfirmCD=
";
URL url=new URL(urlstring);
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
InputStreamReader inputStream=new InputStreamReader(connection.getInputStream());
BufferedReader buffRead=new BufferedReader(inputStream);
......
";
URL url=new URL(urlstring);
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
InputStreamReader inputStream=new InputStreamReader(connection.getInputStream());
BufferedReader buffRead=new BufferedReader(inputStream);
......
* CreateDate 2005-1-21
*/
package com.test;
import java.io.*;import java.net.*;
public class Urltest6 {
public static void main(String [] args){
try{
URL url=new URL("http://member.ecplaza.net/auth.do?MemberID=tradediscovery1&Password=123456&action=login&rurl=http://www.ecplaza.net/InquiryBox/InquiryBox.do?subject=newyear&comments=tttttttttttttttttttttttt&mode=RFQ&id=1894977&clickfrom=M&cmd=send&ConfirmCD=");
HttpURLConnection conn = (HttpURLConnection)url.openConnection();
conn = (HttpURLConnection)url.openConnection();
conn.setDoInput(true);
conn.setRequestMethod("POST");
conn.setAllowUserInteraction(false);
conn.setUseCaches(false);
//String cookie = "ccm=PWD=dfad&UID=%B9%A8%BE%&UniqueID=U020209094506055";
//String cookie = "member_cookie=eXVodWExNjNAZXlvdS5jb218MjY0";
//conn.setRequestProperty("Cookie",cookie);
//System.out.println("\ncookie=:" + cookie);
conn.connect();
// int responseCode = conn.getResponseCode();
// String responseMessage = conn.getResponseMessage();
// System.err.println(responseCode);
// System.err.println(responseMessage);
BufferedReader in=new BufferedReader(new InputStreamReader(conn.getInputStream()));//设置输入流,为了得到返回的HTML
while(in.readLine()!=null){ //如果返回的页面不为空
System.out.println(in.readLine());//得到所有的HTML
}
in.close();
}catch(Exception ex){
System.err.println(ex.getStackTrace());
}
}}为什么我这么写不行呢
{
String result = "";
try{
String urlName = url + "?"+param;
URL U = new URL(urlName);
URLConnection connection = U.openConnection();
connection.connect();
BufferedReader in = new BufferedReader(new InputStreamReader(connection.getInputStream()));
String line;
while ((line = in.readLine())!= null)
{
result += line;
}
in.close();
}catch(Exception e){
System.out.println("没有结果!"+e);
}
return result;
}
public static String sendPost(String url,String param)
{
String result="";
try{
URL httpurl = new URL(url);
HttpURLConnection httpConn = (HttpURLConnection)httpurl.openConnection();
httpConn.setDoOutput(true);
httpConn.setDoInput(true);
PrintWriter out = new PrintWriter(httpConn.getOutputStream());
out.print(param);
out.flush();
out.close();
BufferedReader in = new BufferedReader(new InputStreamReader(httpConn.getInputStream()));
String line;
while ((line = in.readLine())!= null)
{
result += line;
}
in.close();
}catch(Exception e){
System.out.println("没有结果!"+e);
}
return result;
}
如果对方判断了session 或者cookie 就有些麻烦了
谁知道呀
{
String strUrl="http://www.rusbiz.com/send_message.html";
String postdata="formname=send_message";
postdata+="&action=send_message";
postdata+="&sid=send_message";
postdata+="&"+ssid;
postdata+="&lang=en";
postdata+="&cid=52820";
postdata+="&subject=Find 800,000+ FREE buying leads at Bizdiscovery.com";
postdata+="&body="+body;
System.err.println(postdata);
String ss;
StringBuffer s2=new StringBuffer("");
try
{
URL url = new URL(strUrl);
HttpURLConnection conn = (HttpURLConnection)url.openConnection();
conn.setDoOutput(true);
conn.setRequestMethod("POST");
conn.setAllowUserInteraction(false);
conn.setUseCaches(false);
conn.connect();
OutputStreamWriter wr = new OutputStreamWriter(conn.getOutputStream());
wr.write(postdata);
wr.flush();
/*
BufferedReader rd = new BufferedReader(new InputStreamReader(conn.getInputStream()));
while ((ss=rd.readLine())!=null)
{
System.err.println(rd.readLine());
}
*/
wr.close();
//rd.close();
}
catch(Exception e)
{
System.err.println("fabu error");
System.err.println(e.getStackTrace());
}
其中body=Meet 800,000+ global buyer leads from thousands business websites at http://www.bizdiscovery.com. The business info are from 100+ world famous business websites like Alibaba.com,Globalsources.com,ec21.com and it covers the industries from Industrial Supplies,Textiles & Leather, Gifts & Crafts, Apparel Fashion, Home Suppliers, Electronics & Electrical to Construction etc. Make your business easy.<br>
<br>It is Free and simple!<br><br>Visit http://www.bizdiscovery.com now!<br><br>Wishing you every success in business!<br><br>Annie Lam<br>Service Department<br>[email protected]<br><br>http://www.bizdiscovery.com<br>Global Business Search Engine!<br><br>We respect your privacy. If you received this e-mail by mistake or do not wish to receive e-mails from us in the future, we will inactivate your name on our mailing database. Just inform us at Customer Service e-mail:[email protected].<br>在收的时候body只有Meet 800,000+ global buyer leads from thousands business websites at http://www.bizdiscovery.com. The business info are from 100+ world famous business websites like Alibaba.com,Globalsources.com,ec21.com and it covers the industries from Industrial Supplies,Textiles 帮助看看呀
import java.net.*;/**
*
* <p>Title: 将指定的HTTP网络资源在本地以文件形式存放</p>
* <p>Description: </p>
* <p>Copyright: Copyright (c) 2004-2005</p>
*/
public class HttpGet
{
private static int BUFFER_SIZE = 1024; //缓冲区大小 /**
* 构造方法
*/
public HttpGet()
{ } /**
* 根据列表下载资源
*/
public void downLoadByUrl(String downUrl, String fileName) throws IOException
{
saveToFile(downUrl, fileName);
} /**
* 将HTTP资源另存为文件
*
* @param destUrl String
* @param fileName String
* @throws Exception
*/
public void saveToFile(String destUrl, String fileName) throws IOException
{
FileOutputStream fos = null;
BufferedInputStream bis = null;
HttpURLConnection httpUrl = null;
URL url = null;
byte[] buf = new byte[BUFFER_SIZE];
int size = 0;
//建立链接
url = new URL(destUrl);
//打开链接
httpUrl = (HttpURLConnection) url.openConnection();
//连接指定的资源
httpUrl.connect();
//获取网络输入流
bis = new BufferedInputStream(httpUrl.getInputStream());
//DataInputStream bis = new DataInputStream(httpUrl.getInputStream()); //创建目录
File parentDir = new File(fileName).getParentFile();
if( !parentDir.exists() || parentDir.isFile())
{
parentDir.mkdirs();
}
//建立文件
fos = new FileOutputStream(fileName);
//DataOutputStream fos = new DataOutputStream(new FileOutputStream(fileName));
System.out.println("正在获取链接[" + destUrl + "]的内容...\n将其保存为文件[" + fileName +
"]");
System.out.println(new File(fileName).getAbsolutePath());
//保存文件
while ( (size = bis.read(buf)) != -1)
{
fos.write(buf, 0, size);
}
fos.close();
bis.close();
httpUrl.disconnect();
} /**
* 设置代理服务器
*
* @param proxy String
* @param proxyPort String
*/
// public void setProxyServer(String proxy, String proxyPort)
// {
// //设置代理服务器
// System.getProperties().put("proxySet", "true");
// System.getProperties().put("proxyHost", proxy);
// System.getProperties().put("proxyPort", proxyPort);
//
// } /**
* 设置认证用户名与密码
*
* @param uid String
* @param pwd String
*/
// public void setAuthenticator(String uid, String pwd)
// {
// Authenticator.setDefault(new MyAuthenticator(uid, pwd));
// } /**
* 主方法(用于测试)
*
* @param argv String[]
*/
public static void main(String argv[])
{ HttpGet oInstance = new HttpGet();
try
{
//增加下载列表(此处用户可以写入自己代码来增加下载列表) //开始下载
long start = System.currentTimeMillis();
oInstance.downLoadByUrl(
"http://10.78.16.182/downloads/usmro.zip",
"./usmro.zip");
long time = System.currentTimeMillis() - start;
System.out.println("it takes " + time + "to down!");
}
catch (Exception err)
{
System.out.println(err.getMessage());
} }}