Daten via Post an php Script senden

rammi22

Mitglied
Hallo,
ich versuche mit folgenden Script Daten an ein php-Script via POSt zu versenden, ohne Erfolg,. Als GET angehangen gehts...

JAVA
Java:
import java.io.*; 
import java.net.*; 
public class UrlLader2 { 
    
    public static void main( String[] args ){
        
          OutputStream os = null;
          InputStream  is = null;


          try {
              
             // Connection:
             URL           url = new URL( "http://posttestserver.com/post.php" );
             URLConnection con = url.openConnection();
             if( !(con instanceof HttpURLConnection) ) {
                throw new Exception( "Error: Only HTTP allowed." ); 
             }   
             ((HttpURLConnection) con).setRequestMethod( "POST" );
             con.setDoOutput( true );
             // Send data:
             os = con.getOutputStream();
             os.write( "hallo von java ".getBytes() );
             os.flush();
             // Read response:
             is = con.getInputStream();
             int len;
             byte[] buff = new byte[4096];
             while( -1 != (len = is.read( buff )) ) {
                System.out.print( new String( buff, 0, len ) );
             }
             System.out.println();
          } 
          catch( Exception ex ) {
             System.out.println( "\nError: " + ex );
          } 
       }
}

KONSOLE
HTML:
Successfully dumped 0 post variables.View it at http://www.posttestserver.com/data/2015/05/08/04.06.141230003432Post body was 0 chars long.
Das sagt die PHP-Seite
HTML:
...
Headers (Some may be inserted by server)
REQUEST_URI = /post.php
QUERY_STRING = 
REQUEST_METHOD = POST
GATEWAY_INTERFACE = CGI/1.1
REMOTE_PORT = 50334
REMOTE_ADDR = 84.131.70.236
CONTENT_LENGTH = 15
CONTENT_TYPE = application/x-www-form-urlencoded
HTTP_CONNECTION = close
HTTP_ACCEPT = text/html, image/gif, image/jpeg, *; q=.2, */*; q=.2
HTTP_HOST = posttestserver.com
HTTP_USER_AGENT = Java/1.8.0_45
UNIQUE_ID = VUyYptBx6hIAAATQ7tUAAAAD
REQUEST_TIME_FLOAT = 1431083174.0741
REQUEST_TIME = 1431083174

No Post Params.
Empty post body.

Upload contains PUT data: hallo von java

No Post Params? Warum?

Gruss Rammi
 

Zurück
Oben