当前位置: 技术问答>java相关
如何在java的socket程序中使用http的if-modified-since之类的条件?拜托各位救我100分
来源: 互联网 发布时间:2015-05-25
本文导语: 小弟对java一窍不通却被导师要求做这个!到处都找不到例子。 要在这个程序中加入if-modified-since,等有条件的http的get命令? (此程序是从server端得到一个html的文件)。我想用if-modified-since来判断 server的那个html文...
小弟对java一窍不通却被导师要求做这个!到处都找不到例子。
要在这个程序中加入if-modified-since,等有条件的http的get命令?
(此程序是从server端得到一个html的文件)。我想用if-modified-since来判断
server的那个html文件是否被改动过。
谢谢了。下星期再不会我就死定了!
另外这个程序关不掉是怎么回事,有人能帮我改改么?
import java.net.*;
import java.io.*;
public class SimpleWebClient
{
public static void main (String[] args)
{
Socket sock;
InputStream isIn;
PrintStream psOut;
byte abDataIn[] = new byte[1024];
int iNumBytes;
try
{
sock = new Socket ("192.168.0.1", 80);
isIn = sock.getInputStream ();
psOut = new PrintStream (sock.getOutputStream ());
System.out.println ("Clnt: Sending a GET request...");
psOut.println (
"GET /index.html HTTP/1.1 ");
psOut.println ("Connection: Keep-Alive");
psOut.println ("User-Agent: Mozilla/2.0GoldB1 (Win95; I)");
psOut.println ("Pragma: no-cache");
psOut.println ("Host: localhost");
psOut.println ("Accept: image/gif, image/x-xbitmap, "
+ "image/jpeg, image/pjpeg, */*");
psOut.println ("");
System.out.println ("Clnt: Sent a GET request...n");
while (true)
{
iNumBytes = isIn.read (abDataIn, 0, 1024);
if (iNumBytes
要在这个程序中加入if-modified-since,等有条件的http的get命令?
(此程序是从server端得到一个html的文件)。我想用if-modified-since来判断
server的那个html文件是否被改动过。
谢谢了。下星期再不会我就死定了!
另外这个程序关不掉是怎么回事,有人能帮我改改么?
import java.net.*;
import java.io.*;
public class SimpleWebClient
{
public static void main (String[] args)
{
Socket sock;
InputStream isIn;
PrintStream psOut;
byte abDataIn[] = new byte[1024];
int iNumBytes;
try
{
sock = new Socket ("192.168.0.1", 80);
isIn = sock.getInputStream ();
psOut = new PrintStream (sock.getOutputStream ());
System.out.println ("Clnt: Sending a GET request...");
psOut.println (
"GET /index.html HTTP/1.1 ");
psOut.println ("Connection: Keep-Alive");
psOut.println ("User-Agent: Mozilla/2.0GoldB1 (Win95; I)");
psOut.println ("Pragma: no-cache");
psOut.println ("Host: localhost");
psOut.println ("Accept: image/gif, image/x-xbitmap, "
+ "image/jpeg, image/pjpeg, */*");
psOut.println ("");
System.out.println ("Clnt: Sent a GET request...n");
while (true)
{
iNumBytes = isIn.read (abDataIn, 0, 1024);
if (iNumBytes