• 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

PUT request method not working

 
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Ranchers,

I am fairly new to the PUT request method.

I am trying to access file from the url and write some content to the file using PUT request method.

Here is my main method



here are my questions:

1) is there any limit on number of characters to PUT request like GET
2)This program is not working can you please let me know what is the wrong with code
3)If I access the file using PUT request should I write the data in chunks(shown in comments) or can I write the data at one full stretch like I have shown above.

With Regards,
Sridhar
 
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

sridhar gandikota wrote:
1) is there any limit on number of characters to PUT request like GET


No. Unlike a GET, the payload is in the request body, not on the URL.

2)This program is not working can you please let me know what is the wrong with code


What's wrong is your basic assumptions. It makes no sense to make a PUT request to a file. If you think that something will magically update the file, you are mistaken. The PUT request must be made to a servlet or other active element that knows how to deal with PUT requests.

3)If I access the file using PUT request should I write the data in chunks(shown in comments) or can I write the data at one full stretch like I have shown above.


The data should in the body of the request.
 
sridhar gandikota
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Bear Bibeault for your prompt reply.

But what I am trying to do is something like this



java.io.BufferedInputStream in = new java.io.BufferedInputStream(new java.net.URL("http://localhost:9090/test/test.txt";).openStream());
java.io.FileOutputStream fos = new java.io.FileOutputStream("http://localhost:9090/test/test1.txt";);

java.io.BufferedOutputStream bout = new BufferedOutputStream(fos,1024);
byte data[] = new byte[1024];
while(in.read(data,0,1024)>=0)
{
bout.write(data);
}
bout.close();
in.close();




In other words I want to implement poster plugin for firefox browser in java program is this possible
 
Bear Bibeault
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What are you expecting that to do? What's running at localhost:9090?
 
sridhar gandikota
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I just wanted to post some content to file in the URL using java. just wanted to know whether its possible ?

 
Bear Bibeault
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You have not answered by question. What's at localhost:9090?

And again, you can't just make a PUT request to a file at some URL and expect anything special to happen.
 
Rancher
Posts: 4803
7
Mac OS X VI Editor Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You really have to answer @bear's question.

From the small bit of code you have, you are not going to get there, no matter what you are trying to do. You have fundamental concepts all twisted. Something like your:



assumes that you have a HTTP server running and listening to 9090, and that the one line code will work. It won't. You need an Java implementation of the whole HTTP client protocols to make that work reliably, even if it was what you want to do, which I don't think it is.
 
sridhar gandikota
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
After doing a bit of search based on Bears comments on how the PUT request works and also some stuff about the HttpURLConnection.

1) I came to know that we cannot directly access files on the servers and change its contents (magically )
2) I ran some sample programs to understand the concept.

Thanks for guidance Bear and Pat. You guys are simply super, you made my concepts about request methods to be corrected.
 
Your buns are mine! But you can have this 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