• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Partial GET request using Java

 
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello,

I want to write a program to get a part of a file using partial get request. So far I couldn't find a way to do that using Java. Any clues?


Thanks and Regards,
Rajeev
 
Ranch Hand
Posts: 125
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You can't get a file object using GET.

You Need POST method & the enctype should definitely be multipart/formdata, as the file is a binary stuff.

Cheers
Aneesh
 
Bartender
Posts: 9626
16
Mac OS X Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Aneesh Vijendran wrote:You can't get a file object using GET.



On the contrary, most HTTP requests are GET's, and they usually retrieve file objects (html, gif, jpg, etc.). I think you are thinking of uploading a file.
I haven't seen partial GET functionality in the standard API, but Apache HttpClient appears to support it.
 
Aneesh Vijendran
Ranch Hand
Posts: 125
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Well quite political, though!

html/gif/ etc are neither get or post. They jsut come in the response. The request for them might be GET

Cheers
Aneesh
 
Rajeev Sampath
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ok. Thanks both of you for the support.
 
Rajeev Sampath
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
For anyone having similar problems:

I was able to do a partial GET request using Apache HTTP client library.
All I had to do was to add a Range header to the get request as follows:

Range: bytes=x-y

x=starting position
y=ending position

I think this can be done using Java's standard libraries since they should have the facility to add headers.
 
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Aneesh Vijendran wrote:Well quite political, though!


Not at all. Images, JavaScript and CSS are retrieved using an HTTP GET like Joe said; it's as simple as that.
 
Have you no shame? Have you no decency? Have you no tiny ad?
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic