I\'ve asked a question here and I\'ve fixed my problem thanks to an user. This is the code I am using at the moment.
void UploadToDatabase() throws MalformedURLE
The problem lies on this line:
WritableByteChannel rbc = Channels.newChannel(website.openConnection().getOutputStream());
You will need to set doOutput
to true
for this to work. Here's how:
URLConnection urlc = website.openConnection();
urlc.setDoOutput(true);
WritableByteChannel rbc = Channels.newChannel(urlc.getOutputStream());
I am a Java programmer and I have a different solution. Maybe this will be useful for someone.
Just have a look at your advanced proxy settings in your web browser.
System engineers in our company had changed the proxy settings but I was not aware of it.
This error cost me 3 work-days. I got this doOutput error while writing a ftp upload project in my company. I tried everything like adding conn.setDoOutput(true)
or 'fifty shades' of similar solutions but non of them saved me.
But, after I changed my proxy settings to correct ones, the error dissapeared and now I am able to upload my files through ftp using urlConnection in java.
I used the code in the link below to make an upload process, and did not add anything except host, port, user and password.
http://www.ajaxapp.com/2009/02/21/a-simple-java-ftp-connection-file-download-and-upload/
For me it was due to incorrect way of using header, like
HttpEntity<String> entity = new HttpEntity("parameters", headers); //Issue was here
I just made as
HttpEntity<String> entity = new HttpEntity(headers); //Fixed Issue
check here other details