baran_khan
04-30-2008, 04:49 AM
Hi,
I am trying to send an xml String using HTTP Post method. The connection goes well and i receive HTTP_OK as response, but dont know why its not executing the php script where I am sending the data.
Presently I am testing by creating an empty text file on the server side when I hit the page with the POST data.
Here is the code for the two
PHP Code
<?
if($_POST !=NULL){
$file = fopen("text.txt","w+");
}
else{
echo "M here";
}
?>
Here is the code for the connection....
String response;
HttpConnection conn = null;
DataInputStream in = null;
DataOutputStream out = null;
try {
conn = (HttpConnection) Connector
.open("URL",Connector.READ_WRITE);
conn.setRequestMethod(HttpConnection.POST);
out = conn.openDataOutputStream();
out.write("barankhan".getBytes());
out.flush();
out.close();
Dialog.alert("rest"+conn.getResponseCode()+HttpConnection.HTTP_BAD_REQUEST);
in = conn.openDataInputStream();
byte[] data = new byte[200];
int numBytes = in.read(data);
StringBuffer responseBuffer = new StringBuffer();
in.close();
conn.close();
for (int i = 0; i < numBytes; i++) {
responseBuffer.append((char) data[i]);
}
response = responseBuffer.toString();
Dialog.alert(response);
} catch (IOException e) {
System.out.println("Here is exception" + e.getMessage());
}
Hope to hear something great!!!:smile:
I am trying to send an xml String using HTTP Post method. The connection goes well and i receive HTTP_OK as response, but dont know why its not executing the php script where I am sending the data.
Presently I am testing by creating an empty text file on the server side when I hit the page with the POST data.
Here is the code for the two
PHP Code
<?
if($_POST !=NULL){
$file = fopen("text.txt","w+");
}
else{
echo "M here";
}
?>
Here is the code for the connection....
String response;
HttpConnection conn = null;
DataInputStream in = null;
DataOutputStream out = null;
try {
conn = (HttpConnection) Connector
.open("URL",Connector.READ_WRITE);
conn.setRequestMethod(HttpConnection.POST);
out = conn.openDataOutputStream();
out.write("barankhan".getBytes());
out.flush();
out.close();
Dialog.alert("rest"+conn.getResponseCode()+HttpConnection.HTTP_BAD_REQUEST);
in = conn.openDataInputStream();
byte[] data = new byte[200];
int numBytes = in.read(data);
StringBuffer responseBuffer = new StringBuffer();
in.close();
conn.close();
for (int i = 0; i < numBytes; i++) {
responseBuffer.append((char) data[i]);
}
response = responseBuffer.toString();
Dialog.alert(response);
} catch (IOException e) {
System.out.println("Here is exception" + e.getMessage());
}
Hope to hear something great!!!:smile: