BlackBerry Forums Support Community               

Closed Thread
 
LinkBack Thread Tools
Old 04-22-2010, 01:49 AM   #1 (permalink)
New Member
 
Join Date: Apr 2010
Model: 9550
PIN: N/A
Carrier: Developer
Posts: 7
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default Httpconnection Post method problem??

Please Login to Remove!

Hello everyone!
I'm new in BB. I'm trying to work with Httpconnection with Post method.

My problem is the method does not work POST method, it always response 422 error.i dont know what is problem in my code. Please help
Here is my code:

HttpConnection httpConn = null;
String url="link";
InputStream is = null;
OutputStream os = null;

try {

String params="password=123456&username=user";
httpConn = (HttpConnection) Connector.open(url, Connector.READ_WRITE);
httpConn.setRequestMethod(HttpConnection.POST);
httpConn.setRequestProperty("User-Agent",
"Profile/MIDP-2.0 Confirguration/CLDC-1.0");
httpConn.setRequestProperty("Accept_Language", "en-US");

httpConn.setRequestProperty("Content-Type",
"application/x-www-form-urlencoded");

byte[] data=params.getBytes();
httpConn.setRequestProperty("Content-Length", Integer.toString(data.length));

os = httpConn.openOutputStream();
os.write(data);

if (rc != HttpConnection.HTTP_OK) {

throw new IOException("HTTP response code: " + rc);
}

// Read Response from the Server

StringBuffer sb = new StringBuffer();
is = httpConn.openDataInputStream();
int chr;
while ((chr = is.read()) != -1)
sb.append((char) chr);
add(new RichTextField("Source code" + sb.toString()));


}

Last edited by tramorgan : 04-22-2010 at 01:56 AM.
Offline  
Old 04-22-2010, 07:33 AM   #2 (permalink)
BlackBerry Extraordinaire
 
Join Date: Mar 2008
Location: Austin, TX
Model: 9700
PIN: N/A
Carrier: T-Mobile
Posts: 1,644
Post Thanks: 0
Thanked 34 Times in 33 Posts
Default

One observation: your User-Agent header has a mispelled word:

Confirguration...

Should be: Configuration
Offline  
Old 04-22-2010, 07:23 PM   #3 (permalink)
New Member
 
Join Date: Apr 2010
Model: 8330
PIN: N/A
Carrier: AT&T
Posts: 3
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default

That should be it.



HTTP 422 Unprocessable Entity
The request was well-formed but was unable to be followed due to semantic errors.
Offline  
Old 04-22-2010, 09:59 PM   #4 (permalink)
New Member
 
Join Date: Apr 2010
Model: 9550
PIN: N/A
Carrier: Developer
Posts: 7
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks Dougsg38p and robleskein
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

HYDRAULIC CYLINDER RAM ROD FOR MASSEY FERGUSON MF 135 UK 150 165 35 35X 50 65
$18.0
HYDRAULIC CYLINDER RAM ROD FOR MASSEY FERGUSON MF 135 UK 150 165 35 35X 50 65 pictureIBM Any Place Kiosk POS IBM-4838-31E 2GHz (VIA C7-D 2000MHz) 2GB RAM 160GB HD
$109.69
IBM Any Place Kiosk POS IBM-4838-31E 2GHz (VIA C7-D 2000MHz) 2GB RAM 160GB HD  picture"Jai Sai Ram" Decal Vinyl Car i Pad Laptop Window Wall Sticker Removable Item
$8.55
NEW ENERPAC 10 TON RAM RC108
$380.0
NEW ENERPAC 10 TON RAM   RC108 pictureKingston KTH5361/64-CE Simm SDRAM Ram 2087-006.A00 64MB
$9.1
Kingston KTH5361/64-CE  Simm SDRAM Ram 2087-006.A00 64MB picture






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