Google 網路論壇不再支援新的 Usenet 貼文或訂閱項目,但過往內容仍可供查看。

Q: Setting User-Agent Field?

瀏覽次數:132,014 次
跳到第一則未讀訊息

Lawrence Page

未讀,
1996年1月7日 凌晨3:00:001996/1/7
收件者:
I have a web robot which is a Java app. I need to be able to set the
User-Agent field in the HTTP header in order to be a good net citizen (so
people know who is accessing their server). Anyone have any ideas?

Right now, Java sends a request that includes something like:

User-Agent: Java/1.0beta2

I'd rather not rewrite all the HTTP stuff myself. I tried just searching
in the JDK for the Java/1.0beta2 figuring I could just change the string,
but I couldn't find it. Perhaps it is stored as a unicode string?

An easy method of setting the User-Agent field should probably be added to
Java, so people can properly identify their programs.

Thanks, Larry Page

Joseph Millar

未讀,
1996年1月9日 凌晨3:00:001996/1/9
收件者:
Larry,

The User-Agent field is built in:

.\javasrc\src\share\sun\sun\net\www\http\HttpClient.java

It looks to be a concatentation of three items:
1) the system property "http.agent"
2) the word "Java"
3) the system property "java.version"

Since the agent string that gets built has only items 2 and
3, perhaps that means "http.agent" is blank (i.e. settable)?
If you could set "http.agent" prior to establishing the URL
connection, you may be able to get the desired effect.

Just a shot in the dark...


Joe Millar

In article <page-07019...@qwerty.stanford.edu>, pa...@cs.stanford.edu
says...

0 則新訊息