可用分范围内随意挑,另送126.com的1g邮箱一个.up有分.不够另开贴补.只求关于socket的web解决方案

wuyaxlz 2004-10-24 11:48:36
1、
import java.net.*;
import java.io.*;
import java.util.*;

public class HTTPForm extends Properties{

public static void main(String[] args) throws Exception{
HTTPForm test = new HTTPForm();
Socket sock=new Socket("www.163.com",80);
OutputStream output=sock.getOutputStream();
InputStream input=sock.getInputStream();
BufferedReader br = new BufferedReader(new InputStreamReader(input));
//test.put("user_id","1");
test.send("index.html",output);
System.out.print(br.readLine());
sock.close();
}

public boolean send(String page,OutputStream outstr)throws IOException
{
StringBuffer data=new StringBuffer();
String headers;
Enumeration i=keys();
while(i.hasMoreElements())
{
String key=(String)i.nextElement();
data.append(URLEncoder.encode(key)+"="+URLEncoder.encode((String)get(key))+"&");
}
if(data.length()>0)
{
data.deleteCharAt(data.length()-1);
}
headers="POST "+page+" HTTP/1.1\r\n";
//headers+="Accept: image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, application/vnd.ms-powerpoint, application/vnd.ms-excel, application/msword, */*/r/n";
// headers+="Accept-Language: zh-cn\r\n";
// headers+="Accept-Encoding: gzip, deflate\r\n";
// headers+="User-Agent: Mozilla/4.0 (compatible; MSIE 4.01; Windows 2000)\r\n";
//headers+="Connection:Keep-Alive\r\n";
//headers+="Host: localhost:8080\r\n";
headers+="Content-type: application/x-www-form-urlencoded \r\n";
headers+="Content-Length: "+data.length()+"\r\n\r\n";
//data= URLEncoder.encode(page);
outstr.write(headers.getBytes());
outstr.write(data.toString().getBytes());
return true;
}

}

2、
如何得到服务器给出的session

解决任何一个就可以.在线等
...全文
165 9 打赏 收藏 转发到动态 举报
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
wuyaxlz 2004-10-27
  • 打赏
  • 举报
回复

http://www.netyi.net/in.asp?id=wuyaxlz
takecare 2004-10-27
  • 打赏
  • 举报
回复
用HttpURLConnection,不就行了。
String cookieVal = huc.getHeaderField("Set-Cookie");
String sessionId = cookieVal.substring(0, cookieVal.indexOf(";"));
wuyaxlz 2004-10-24
  • 打赏
  • 举报
回复
各位大大,帮帮忙呀
whyandwhat 2004-10-24
  • 打赏
  • 举报
回复
接分来了
wuyaxlz 2004-10-24
  • 打赏
  • 举报
回复
各位大大,帮帮忙呀
wuyaxlz 2004-10-24
  • 打赏
  • 举报
回复
asp的post 救命
wuyaxlz 2004-10-24
  • 打赏
  • 举报
回复
post 一个页面
好象头文件有点问题,明明在的页面
他提示HTTP/1.0 400 Bad RequestFinished executing
所以请各位帮忙

不用servlet,我这里是客户端.用socket,url之类的
wjsfr 2004-10-24
  • 打赏
  • 举报
回复
第一个问题:你到底要做什么呢?
第二个问题要用到servlet,在HttpServlet类中有个方法叫getSession()就可以得到HttpSession对象
vongood 2004-10-24
  • 打赏
  • 举报
回复
mark first

67,515

社区成员

发帖
与我相关
我的任务
社区描述
J2EE只是Java企业应用。我们需要一个跨J2SE/WEB/EJB的微容器,保护我们的业务核心组件(中间件),以延续它的生命力,而不是依赖J2SE/J2EE版本。
社区管理员
  • Java EE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧