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

NEW Siemens Inverter IGBT module 6SY7000-0AE73 for industry use
$100.0
NEW Siemens Inverter IGBT module 6SY7000-0AE73 for industry use picture6Se64402ud222ba1 6Se6 440-2Ud22-2Ba1 Siemens Inverter New W
$536.97
6Se64402ud222ba1 6Se6 440-2Ud22-2Ba1 Siemens Inverter New W pictureWild Heerbrugg M40 Inverted Microscope stand
$100.0
Wild Heerbrugg M40 Inverted Microscope stand pictureTC 2.2kw 5A Frequency Inverter Converter general vector type 380V IC+IGBT RS485
$158.9
TC 2.2kw 5A Frequency Inverter Converter general vector type 380V IC+IGBT RS485 picture1PC NEW YASKAWA INVERTER Motherboard ETC616760-S1114 #0H08
$959.99
1PC NEW YASKAWA INVERTER Motherboard ETC616760-S1114 #0H08 picture






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