Skip to Main Content

Java Programming

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Interested in getting your voice heard by members of the Developer Marketing team at Oracle? Check out this post for AppDev or this post for AI focus group information.

java.net.ProtocolException: cannot write to a URLConnection

910067Jan 10 2012 — edited Jan 16 2012
I want to upload a file to a computer in the network. There is proxy so i had to set proxy settings but ı've got this exception:
java.net.ProtocolException: cannot write to a URLConnection if doOutput=false - call setDoOutput(true)
I couldn't solve this exception.

Here is my code :
StringBuffer filePath = new StringBuffer("file:\\\\10.253.8.77\\Folder");
Properties sysProperties = System.getProperties();

sysProperties.put("http.proxyHost", "proxy.XXX.intra");
sysProperties.put("http.proxyPort", "80");
sysProperties.put("http.proxySet", "true");

URL url = new URL( filePath.toString() );
URLConnection urlc = url.openConnection();
urlc.setDoInput (true);
urlc.setDoOutput (true);
urlc.setUseCaches(false);

urlc.setRequestProperty ("Content-Type", "application/x-www-form-urlencoded");
urlc.setAllowUserInteraction(true);

DataOutputStream dataOutputStream = (DataOutputStream)urlc.getOutputStream();

String content = "USERNAME=" + URLEncoder.encode ("XXXX") + "&PASSWORD=" + URLEncoder.encode ("987654321");

dataOutputStream.writeBytes (content);

//dataOutputStream.write(file.getFileData());
dataOutputStream.flush();
dataOutputStream.close();
This post has been answered by DrClap on Jan 11 2012
Jump to Answer

Comments

Processing
Locked Post
New comments cannot be posted to this locked post.

Post Details

Locked on Feb 13 2012
Added on Jan 10 2012
10 comments
5,658 views