BlackBerry Forums Support Community               

Closed Thread
 
LinkBack Thread Tools
Old 03-13-2009, 03:55 PM   #1 (permalink)
New Member
 
Join Date: Mar 2009
Model: 8330
PIN: N/A
Carrier: Rogers
Posts: 2
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default HTTP POST and passing parameters in URLs

Please Login to Remove!

Hi all,

I am working on an app where we have to pass parameters to a web app using HTTP POST in a HTTPS URL in the form of:

example.com/path/app.asmx/Function?Param1=123456&Param2=098765

We are expecting an XML response in the form of
<?xml version="1.0" encoding="utf-8"?>
<string xmlns="example.com/path/">response</string>

I am not sure how to set up a connection to do this and how to make the program extract the string from the response. Any help would be much appreciated.
Offline  
Old 03-14-2009, 07:42 PM   #2 (permalink)
BlackBerry Extraordinaire
 
Join Date: Jan 2006
Model: LEZ10
OS: 10.0.10
Carrier: Rogers CA
Posts: 1,704
Post Thanks: 20
Thanked 77 Times in 68 Posts
Default

Putting parameters in the URL is not the HTTP POST protocol, but you just include the parameters in the URL as you have it coded there (with the https:// prefix of course, eg):

Code:
HttpConnection http = (HttpConnection)Connector.open("https://example.com/path/app.asmx/Function?Param1=123456&Param2=098765");

 returnCode = http.getResponseCode();
 String returnMessage = http.getResponseMessage();
 InputStream in = http.openInputStream();
                        
 returnContentType = http.getType();
            
 int cl = (int)http.getLength();
 if (cl > 0)
 {
    byte[] buf = new byte[cl];
    in.read(buf);
    returnContent = new String(buf);
 }
 else
 {
    StringBuffer sb = new StringBuffer();
    byte[] buf = new byte[1024];
    int n = 0;
                            
    while ((n = in.read(buf)) > 0)
    {
       sb.append(new String(buf,0,n));
    }
    returnContent = sb.toString();
 }
                        
 in.close();
 http.close();
Offline  
Old 03-15-2009, 06:41 PM   #3 (permalink)
Thumbs Must Hurt
 
Join Date: Nov 2008
Location: Sioux Falls, SD
Model: 9530
PIN: N/A
Carrier: Verizon Wireless
Posts: 65
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default

The problem with simply appending the parameters onto the URL is that you're actually making a GET request. Some APIs will reject a GET when they're expecting a POST, others will simply handle it.

Making a POST Request

Code:
HttpConnection oCon = (HttpConnection)Connection.open("http://example.com/path/app.asmx/Function");

URLEncodedPostData oPostData = new URLEncodedPostData(URLEncodedPostData.DEFAULT_CHARSET, false);

post.append("param1", "ThisIsTheValueOfParam1");
post.append("param2", "ABC123");

OutputStream strmOut = oCon.openOutputStream();
strmOut.write(oPostData.getBytes());

strmOut.flush();
strmOut.close();
** I typed this out, so there maybe some spelling mistakes

HRBUCKLEY's example is good for getting the return data as a String. You'll then have to write some code to parse the XML. I prefer the SAXParser.
__________________
Handspring >> Palm >> BB Pearl >> BB Storm

Tumblog: http://www.geekkink.com
Blog: http://www.zechariahs.org/blog

Last edited by zechariahs : 03-15-2009 at 06:44 PM.
Offline  
Old 03-15-2009, 09:53 PM   #4 (permalink)
New Member
 
Join Date: Mar 2009
Model: 8330
PIN: N/A
Carrier: Rogers
Posts: 2
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default

hrbuckley, that did the trick, thank you very much.
zechariahs, thanks for the reply.
Offline  
Closed Thread


Thread Tools

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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

SMPTE Output Studio 16 Extras The Complete SMPTE Generator For Your Amiga
$14.99
SMPTE Output Studio 16 Extras The Complete SMPTE Generator For Your Amiga picture23 WAY "D" SHELL HOOD DB23 D23 DB23F DB23M FOR COMMODORE AMIGA CONNECTORS - RARE
$2.54
23 WAY Toshiba TMP68HC000P-16 16mhz 68000 CPU Chip, Amiga Atari Apple Mac
$22.0
Toshiba TMP68HC000P-16 16mhz 68000 CPU Chip, Amiga Atari Apple Mac pictureAMIGA AMIGA A107-335D RQAUS1
$36.1
AMIGA AMIGA A107-335D RQAUS1 pictureCommodore AMIGA CSG 8520 Chip IC 500/A500+/A2000 CDTV - NEW
$12.99
Commodore AMIGA CSG 8520 Chip IC  500/A500+/A2000 CDTV - NEW picture






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