?
Solved

obtaining URL filename

Posted on 2003-03-08
14
Medium Priority
?
244 Views
Last Modified: 2010-04-06
Hi,
I'm working on a java application that needs to retrieve a url's filename (if there is one).
But how do you get the filename of a url like this,
http://www.somesite.com/getfile.php?site=1&file=112&gfile=yes (I've changed the site's name for privacy but it's a real url).
I know it points to a file because it initiates a filedownload and I can retrieve the file contents easily.
I've tried examining the headers for "Content-Disposition" and "Content-Location" but they're not returned by the server. Do I need to send a particular "User-Agent" header to get these values?
The same question also applies to jsp and asp downloads.
0
Comment
Question by:halogen
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
  • 3
  • +3
14 Comments
 
LVL 17

Expert Comment

by:dorward
ID: 8093885
A URL points to a resource, the webserver is under no obligation to link that resource to a _file_, or even suggest a file name.
0
 
LVL 1

Expert Comment

by:tomt84
ID: 8095781
If I understand your question right, you can get the original URL from HTTP headers using the PATH_INFO, QUERY_STRING, SCRIPT_NAME, SERVER_NAME, and URL headers. Just try grabbing the contents of those to see which is most suitable. You may find that if you concantate (sp?) some of those strings together you may find what you're looking for. I assume PHP gives you some way to get at the HTTP headers like ASP does (request.servervariables(""))
0
 

Expert Comment

by:mcaxiak
ID: 8096971
Well, I hope this helps...
I don't know Java well enough to offer you any help. (Except that in javascript you can go top.location for the address.) Maybe the environment variables used here can be used in the same method in Java.
This does not post. (In order to post I think you may need to use the XML parser and post data to a web site (ughh)).

This is in ASP (could you tell? ;))
<%
Dim FullURL
FullURL = "http://" & Request.ServerVariables("HTTP_HOST") &  Request.ServerVariables("URL")
If Request.ServerVariables("QUERY_STRING") <> "" Then _
     FullURL = FullURL & "?"
FullURL = FullURL & Request.ServerVariables("QUERY_STRING")

Response.Write FullURL
%>

PHP
<?
$full_url = 'http://' . $_SERVER['SERVER_NAME'] . $_SERVER['SCRIPT_NAME'];
if ($_SERVER['QUERY_STRING'] != '') {
$full_url = $full_url . '?';
}
$full_url = $full_url . $_SERVER['QUERY_STRING'];

echo $full_url;
?>
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 4

Expert Comment

by:anderson22
ID: 8122364
java or jsp/servlets?

Is this a web application?

if this is a web application (such as JSP), you can retrieve the server variables, particularly the SCRIPT_NAMe like tomt84
0
 

Author Comment

by:halogen
ID: 8130263
Hi,
I think I may have caused some confusion with this question, so I'll try to clarify (although I think dorward is right and there is no consistent method).
My java application is a client program that connects to a web server for the purpose of retrieving a url's contents (in the same way that a web browser would).
If my application wants to save the contents (eg. a file download) it would like to suggest a filename based on information returned by the webserver. In the case of a "normal" url this is simply done by examining the url. But if the server uses asp or php the actual name of the resource is hidden. I know it's possible to retrieve the resource's filename because a web browser like Internet Explorer can do it.
The suggested way to do this is using the "Content-Disposition" header (RFC 2616) but this does not always work.
I'm leaving this question open in the event anyone has an answer.
0
 
LVL 4

Expert Comment

by:anderson22
ID: 8130427
This is something that has to be provided by the page (just the mime type, etc.)
0
 

Author Comment

by:halogen
ID: 8173239
There has not been a satisfactory answer to this question.
As a result I would like to close this thread.
0
 
LVL 17

Expert Comment

by:dorward
ID: 8173532
Post a message in community support then.
0
 

Expert Comment

by:modulo
ID: 8183469
Dear expert(s),

A request has been made to close this Q in CS:
http://www.experts-exchange.com/Community_Support/CleanUp/Q_20557547.html

Without a response in 72 hrs, a moderator will finalize this question by:

 - Saving this Q as a PAQ and refunding the points to the questionner

When you agree or disagree, please add a comment here.

Thank you.

modulo

Community Support Moderator
Experts Exchange
0
 
LVL 1

Expert Comment

by:tomt84
ID: 8184312
I believe that there are two issues here:

1) The question was slightly ambiguous

2) The answers provided by myself, anderson22, and mcaxiak demonstrate at least 3 different ways to accomplish the task set, i.e. the original URL of a request can be provided by one or more different http headers strung together. If this is not what the question author was looking for then my point #1 is supported. If this solution is what the author required then I believe s/he wants the points refunding after having gained an acceptable pointer in the right direction if not a direct answer. Maybe if the author could submit some clarification and/or source code then we would be better able to work something out.

Regards
Tomt84
0
 

Author Comment

by:halogen
ID: 8186001
tomt84,
As I tried to clarify, this is not a server app, nor is it an applet that runs within a browser, therefore the answers provided are not appropiate to this question. The headers that you mentioned are PHP variables that can be set to send information to the client, there is no way for the client to access these values except as standard http headers eg "Content-Type", my problem was that these headers were not always being sent by the server.
0
 
LVL 4

Expert Comment

by:anderson22
ID: 8186781
If you use the HTTP protocol, standards implemented by W3C propose that headers are a standard for communication.  No application must follow these guidelines, but they are not compliant if they do not.

Now, if you are using regular socket (client/server) communication. There is no definition that says a header or any information is required.

HTTP is a protocol with a defined structure.

-rca
0
 

Expert Comment

by:modulo
ID: 8194585
Question looks active again.
Will check for proposal how to close this Q after 72 hrs.

Thank you.

modulo

Community Support Moderator
Experts Exchange
0
 

Accepted Solution

by:
modulo earned 0 total points
ID: 8221438
Saving this Q as a PAQ and refunding the 20 points to the questionner

modulo

Community Support Moderator
Experts Exchange
0

Featured Post

Get 15 Days FREE Full-Featured Trial

Benefit from a mission critical IT monitoring with Monitis Premium or get it FREE for your entry level monitoring needs.
-Over 200,000 users
-More than 300,000 websites monitored
-Used in 197 countries
-Recommended by 98% of users

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
Originally, this post was published on Monitis Blog, you can check it here . In business circles, we sometimes hear that today is the “age of the customer.” And so it is. Thanks to the enormous advances over the past few years in consumer techno…
Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:
The viewer will learn how to count occurrences of each item in an array.
Suggested Courses

777 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question