I am confused I am trying to make a post with a java client but it is not working. Serever responses say OK but it is not ok.
I wa debbunging and I watched out writes but I don't know what is wrong.
Help me please.
:::::::::::::::::::::::::::::::::::
JAVA client
:::::::::::::::::::::::::::::::::::
import java.net.*;
import java.io.*;
public class Post {
public static void main(String[] args) {
//variables y obejtos
String str;
String post;
DataOutputStream out;
URL url=null;
HttpURLConnection conexion=null;
str="http://localhost/applet/post.php";
post="cadena=ya_haz_el_post";
try
{url=new URL(str);}
catch(MalformedURLException exurl)
{System.err.println("ERROR en el URL java dice: \n\t"+exurl);}
try{
conexion=(HttpURLConnection)url.openConnection();
conexion.setRequestMethod("POST");
conexion.setRequestProperty("Content-type", "application/x-form-urlencode");
conexion.setRequestProperty("Content-Length", Integer.toString(post.length() ) );
conexion.setDoOutput(true);
conexion.setDoInput(true);
out=new DataOutputStream(conexion.getOutputStream() );
out.writeUTF(post);
out.flush();
if ( conexion.getResponseCode() != HttpURLConnection.HTTP_OK )
System.out.println(" Ya");
else {
System.err.println(" NO Server Response:"+conexion.getResponseMessage() );
return;
}
conexion.disconnect();
}
catch(IOException exio)
{System.err.println("ERROR java dice: \n\t"+exio);}
}
}
==========================
This makes out:
NO Server Response:Ok
And in $argc is =0 in the following php
=======================
I also tried with a perl script
::::::::::::::::::::::::::::::::::::::::::::::::::::
PHP script
::::::::::::::::::::::::::::::::::::::::::::::::::::
<?php
$argc=count($_POST);
$str=$_POST['cadena'];
$str=utf8_decode($str);
if($argc==0)
$str= "NO ARGC=0" ;
else if( ($argc>0) &&($str) )
$str="YA".$str;
else
$str="UNKNOW" ;
$hFILE=fopen("/tmp/archi.txt","w+");
if( fwrite($hFILE,$str)==FALSE )
die("NO");
?>
::::::::::::::::::::::::::::::::::::::
access.log
::::::::::::::::::::::::::::::::::::::
127.0.0.1 - - [13/Nov/2006:01:25:29 -0600] "POST /applet/post.php HTTP/1.1" 200 - "-" "Java/1.5.0_07"
I wa debbunging and I watched out writes but I don't know what is wrong.
Help me please.
:::::::::::::::::::::::::::::::::::
JAVA client
:::::::::::::::::::::::::::::::::::
import java.net.*;
import java.io.*;
public class Post {
public static void main(String[] args) {
//variables y obejtos
String str;
String post;
DataOutputStream out;
URL url=null;
HttpURLConnection conexion=null;
str="http://localhost/applet/post.php";
post="cadena=ya_haz_el_post";
try
{url=new URL(str);}
catch(MalformedURLException exurl)
{System.err.println("ERROR en el URL java dice: \n\t"+exurl);}
try{
conexion=(HttpURLConnection)url.openConnection();
conexion.setRequestMethod("POST");
conexion.setRequestProperty("Content-type", "application/x-form-urlencode");
conexion.setRequestProperty("Content-Length", Integer.toString(post.length() ) );
conexion.setDoOutput(true);
conexion.setDoInput(true);
out=new DataOutputStream(conexion.getOutputStream() );
out.writeUTF(post);
out.flush();
if ( conexion.getResponseCode() != HttpURLConnection.HTTP_OK )
System.out.println(" Ya");
else {
System.err.println(" NO Server Response:"+conexion.getResponseMessage() );
return;
}
conexion.disconnect();
}
catch(IOException exio)
{System.err.println("ERROR java dice: \n\t"+exio);}
}
}
==========================
This makes out:
NO Server Response:Ok
And in $argc is =0 in the following php
=======================
I also tried with a perl script
::::::::::::::::::::::::::::::::::::::::::::::::::::
PHP script
::::::::::::::::::::::::::::::::::::::::::::::::::::
<?php
$argc=count($_POST);
$str=$_POST['cadena'];
$str=utf8_decode($str);
if($argc==0)
$str= "NO ARGC=0" ;
else if( ($argc>0) &&($str) )
$str="YA".$str;
else
$str="UNKNOW" ;
$hFILE=fopen("/tmp/archi.txt","w+");
if( fwrite($hFILE,$str)==FALSE )
die("NO");
?>
::::::::::::::::::::::::::::::::::::::
access.log
::::::::::::::::::::::::::::::::::::::
127.0.0.1 - - [13/Nov/2006:01:25:29 -0600] "POST /applet/post.php HTTP/1.1" 200 - "-" "Java/1.5.0_07"
