BlackBerry Forums Support Community
              

Closed Thread
 
Thread Tools
Old 03-13-2009, 03:55 PM   #1
BBTeam
New Member
 
Join Date: Mar 2009
Model: 8330
PIN: N/A
Carrier: Rogers
Posts: 2
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
hrbuckley
BlackBerry Extraordinaire
 
Join Date: Jan 2006
Model: LEZ10
OS: 10.0.10
Carrier: Rogers CA
Posts: 1,704
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
zechariahs
Thumbs Must Hurt
 
Join Date: Nov 2008
Location: Sioux Falls, SD
Model: 9530
PIN: N/A
Carrier: Verizon Wireless
Posts: 65
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
BBTeam
New Member
 
Join Date: Mar 2009
Model: 8330
PIN: N/A
Carrier: Rogers
Posts: 2
Default

hrbuckley, that did the trick, thank you very much.
zechariahs, thanks for the reply.
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


BISSELL 3-in-1 Turbo Lightweight Stick Vacuum, 2610 (Black) picture

BISSELL 3-in-1 Turbo Lightweight Stick Vacuum, 2610 (Black)

$37.96



Bissell 3-in-1 Lightweight Corded Stick Vacuum 2030 picture

Bissell 3-in-1 Lightweight Corded Stick Vacuum 2030

$28.88



4.5 CFM Single-Stage Rotary Vacuum Pump HVAC/Auto AC 4.5CFM 1/3HP 1/4

4.5 CFM Single-Stage Rotary Vacuum Pump HVAC/Auto AC 4.5CFM 1/3HP 1/4"ACME inlet

$45.98



Shop Vacuum upholstery extractor conversion kit auto vac detail carpet or home.  picture

Shop Vacuum upholstery extractor conversion kit auto vac detail carpet or home.

$192.00



3 CFM Air Vacuum Pump HVAC Manifold Gauge Set AC A/C Refrigeration Kit picture

3 CFM Air Vacuum Pump HVAC Manifold Gauge Set AC A/C Refrigeration Kit

$46.03



VEVOR 5 Gallon Vacuum Chamber with 5CFM Vacuum Pump Kit 1/3HP Single Stage 110V picture

VEVOR 5 Gallon Vacuum Chamber with 5CFM Vacuum Pump Kit 1/3HP Single Stage 110V

$104.99







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