I
igoR Buttler
Hi everybody,
I'm trying to post a file to my server but am having quite some issues. I
open the HttpURLConnection and then try to get the outputstream. When I do
this I get a
"java.net.ProtocolException: Cannot write output after reading input.". In
my understanding this error occurs when you try to write to the outputstream
when you have already read from the inputstream but here I am only trying to
get the outputstream without writing to anyhing. My code is attached below.
Any suggestions?
public void openConnection()
{
try
{
URL pisces = new URL(url);
urlConnection = (HttpURLConnection)pisces.openConnection();
urlConnection.setDoInput(true);
urlConnection.setDoOutput(true);
urlConnection.setAllowUserInteraction(false);
urlConnection.setUseCaches(false);
urlConnection.setRequestMethod("POST");
}
catch (Exception e)
{
e.printStackTrace(System.out);
}
}
private void sendJar()
{
openConnection();
BufferedReader in = null;
DataOutputStream out = null;
try
{
out = new DataOutputStream(urlConnection.getOutputStream());
...Excepeion is thrown here
I'm trying to post a file to my server but am having quite some issues. I
open the HttpURLConnection and then try to get the outputstream. When I do
this I get a
"java.net.ProtocolException: Cannot write output after reading input.". In
my understanding this error occurs when you try to write to the outputstream
when you have already read from the inputstream but here I am only trying to
get the outputstream without writing to anyhing. My code is attached below.
Any suggestions?
public void openConnection()
{
try
{
URL pisces = new URL(url);
urlConnection = (HttpURLConnection)pisces.openConnection();
urlConnection.setDoInput(true);
urlConnection.setDoOutput(true);
urlConnection.setAllowUserInteraction(false);
urlConnection.setUseCaches(false);
urlConnection.setRequestMethod("POST");
}
catch (Exception e)
{
e.printStackTrace(System.out);
}
}
private void sendJar()
{
openConnection();
BufferedReader in = null;
DataOutputStream out = null;
try
{
out = new DataOutputStream(urlConnection.getOutputStream());
...Excepeion is thrown here