BlackBerry Forums Support Community
              

Closed Thread
 
Thread Tools
Old 04-30-2008, 04:49 AM   #1
baran_khan
Thumbs Must Hurt
 
baran_khan's Avatar
 
Join Date: Apr 2008
Model: 9500
PIN: N/A
Carrier: Airtel
Posts: 110
Default Trouble Sending using POST over Http Connection

Please Login to Remove!

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....


PHP Code:

        String response
;
        
HttpConnection conn null;
        
DataInputStream in null;
        
DataOutputStream out null;
        try {
            
conn = (HttpConnectionConnector
                    
.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();
            
bytexxx91;xxx93; data = new bytexxx91;200xxx93;;
            
int numBytes in.read(data);
            
StringBuffer responseBuffer = new StringBuffer();
            
in.close();
            
conn.close();
            for (
int i 0numBytesi++) {
                
responseBuffer.append((chardataxxx91;ixxx93;);
            }
            
response responseBuffer.toString();
            
Dialog.alert(response);
        } catch (
IOException e) {
            
System.out.println("Here is exception" e.getMessage());
        } 
Hope to hear something great!!!

Last edited by baran_khan; 04-30-2008 at 05:02 AM..
Offline  
Old 04-30-2008, 05:00 AM   #2
Ivanov
Talking BlackBerry Encyclopedia
 
Join Date: Apr 2008
Location: Germany, BW
Model: -
PIN: N/A
Carrier: -
Posts: 310
Default

hi.
please use [code] tags - it makes your code much easier to read.

have you tried to make y post using another client? webpage in the desktop browser?

is your php code executed?
Offline  
Old 04-30-2008, 05:05 AM   #3
baran_khan
Thumbs Must Hurt
 
baran_khan's Avatar
 
Join Date: Apr 2008
Model: 9500
PIN: N/A
Carrier: Airtel
Posts: 110
Default

Hi,

Thanks for the reply,

Yeah the PHP code is running perfectly on local machine...I have uploaded it to the server so that I can access it through blackberry. The thing is The code executes without any issues and I get HTTP 200 as the response i.e. HTTP_OK. But the file is not created, so I guess I am able to hit the URL but not able to assign the post variable.

I tried inputStream on the page and received the else part of the page executed as response.

Thanks for the reply!!
Offline  
Old 04-30-2008, 05:21 AM   #4
Ivanov
Talking BlackBerry Encyclopedia
 
Join Date: Apr 2008
Location: Germany, BW
Model: -
PIN: N/A
Carrier: -
Posts: 310
Default

try adding
Code:
conn.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
Offline  
Old 04-30-2008, 05:24 AM   #5
baran_khan
Thumbs Must Hurt
 
baran_khan's Avatar
 
Join Date: Apr 2008
Model: 9500
PIN: N/A
Carrier: Airtel
Posts: 110
Default

Nope

I did tried earlier...not working...i tried to send simple string, xml with the mentioned content type..but not working....
Offline  
Old 04-30-2008, 06:39 AM   #6
Ivanov
Talking BlackBerry Encyclopedia
 
Join Date: Apr 2008
Location: Germany, BW
Model: -
PIN: N/A
Carrier: -
Posts: 310
Default

you have to send a key-value pair in your post like "name=barankhan"

this works for me:

PHP Code:
<?php
$file 
fopen("postvars.txt""w");

foreach(
$_POST as $key => $value) {
  print(
$key." => ".$value."\n");
  
fwrite($file$key." => ".$value."\n");
}

fclose($file);
?>
PHP Code:
...
conn = (HttpConnectionConnector.open(url,Connector.READ_WRITE);
conn.setRequestMethod(HttpConnection.POST);
conn.setRequestProperty("Content-Type""application/x-www-form-urlencoded");
out conn.openDataOutputStream();
out.write("name=me".getBytes());
out.flush();
out.close();

... 
Offline  
Old 04-30-2008, 07:28 AM   #7
baran_khan
Thumbs Must Hurt
 
baran_khan's Avatar
 
Join Date: Apr 2008
Model: 9500
PIN: N/A
Carrier: Airtel
Posts: 110
Default

just how do u get to a thing I dont even think of......it worked like anything...Dont know how I can pay back....I really appreciate ur efforts..thanks!!!

Last edited by baran_khan; 05-01-2008 at 04:34 AM..
Offline  
Old 04-30-2008, 07:40 AM   #8
Ivanov
Talking BlackBerry Encyclopedia
 
Join Date: Apr 2008
Location: Germany, BW
Model: -
PIN: N/A
Carrier: -
Posts: 310
Default

you are welcome
Offline  
Old 04-30-2008, 07:41 AM   #9
jfisher
CrackBerry Addict
 
Join Date: Jun 2005
Location: Manchester, UK
Model: BOLD
Carrier: t-mobile
Posts: 714
Default

----
__________________
new job doesn't allow a public profile - please do not contact this user with questions, you will not get a response. good luck!
Offline  
Old 05-06-2008, 08:12 AM   #10
baran_khan
Thumbs Must Hurt
 
baran_khan's Avatar
 
Join Date: Apr 2008
Model: 9500
PIN: N/A
Carrier: Airtel
Posts: 110
Default Send Image over HTTP Connection

Okey,

Here is new thing about sending data over HTTP Connection. Now the requirement is to send an Image over the connection. I have managed to send it in chunks using Base64 encoding in the form of string, but when i asseble the same on the other side, it gets corrupted.

Any intelligent guesses about how we can achieve it.....
__________________
Smart People ask for Help!!!
Offline  
Closed Thread



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


MSA ALTAIR 4XR picture

MSA ALTAIR 4XR

$700.00



MSA altair 4X multi gas meter Monitor detector, O2,H2S,CO,LEL Charger calibrated picture

MSA altair 4X multi gas meter Monitor detector, O2,H2S,CO,LEL Charger calibrated

$340.00



MSA Altair 5 Gas Detector  picture

MSA Altair 5 Gas Detector

$98.99



MSA Altair 5X Gas Detector Meter *Recently Calibrated and 30 Day Warranty* picture

MSA Altair 5X Gas Detector Meter *Recently Calibrated and 30 Day Warranty*

$795.00



MSA 10042621 Altair 5X Sampling Probe Straight Air-Line 1' Color Black (E2) picture

MSA 10042621 Altair 5X Sampling Probe Straight Air-Line 1' Color Black (E2)

$295.00



Msa Altair 4XR picture

Msa Altair 4XR

$372.60







Copyright © 2004-2016 BlackBerryForums.com.
The names RIM © and BlackBerry © are registered Trademarks of BlackBerry Inc.