1

I was try to send data to the url http://mahavidyalay.in/AcademicDevelopment/ServerDemo/Led10.php?status=1 but it showing me error:

java.net.ProtocolException: Cannot write output after reading input.

I think error is occurring because of line int responseCode = connection.getResponseCode(); And I don't know how to solve this.

    URL Transmeter_Url = new URL(data);
    HttpURLConnection connection = (HttpURLConnection) Transmeter_Url.openConnection();
    connection.setRequestMethod("POST");
    connection.setDoOutput(true);
    connection.setDoInput(true);
    connection.setUseCaches(false);

    connection.setRequestProperty("Content-Type",Contetn_Type);
    connection.setRequestProperty("Contetn-Length", Integer.toString(Post_Value.length()));
    connection.setRequestProperty("User-Agent", "Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10.4; en- 
    US; rv:1.9.2.2) Gecko/20100316 Firefox/3.6.2");

    int responseCode = connection.getResponseCode();
    System.out.println("Get Response code:"+responseCode);

    System.out.println("Reached here 7");

    OutputStream outputStream = connection.getOutputStream();

    System.out.println("Reached here 7");

    outputStream.write(Post_Value.getBytes());
    outputStream.flush();
    outputStream.close();
Premlatha
  • 1,676
  • 2
  • 20
  • 40

0 Answers0