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

Mitel IP-5330e VoIP Display Phone 50006476 W/Cordless Headset 50005712 56008569A
$332.99
Mitel IP-5330e VoIP Display Phone 50006476 W/Cordless Headset 50005712 56008569A pictureDigium Switchvox 80 VOIP IP PBX 1U Rack Appliance NEW part # 1AS80001OLF
$509.0
Digium Switchvox 80 VOIP IP PBX 1U Rack Appliance NEW part # 1AS80001OLF pictureDigium Switchvox 80 Asterisk VoIP System 2AS80001LF-
$150.0
Digium Switchvox 80 Asterisk VoIP System 2AS80001LF- pictureCisco CP-7975G Unified IP Phone VoIP - NIB
$225.0
Cisco CP-7975G Unified IP Phone VoIP - NIB picture AVAYA 4620 IP Phone VoIP sip pots not completely tested programmable
$24.95
 AVAYA 4620 IP Phone VoIP sip pots not completely tested programmable picture






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