BlackBerry Forums Support Community               

Closed Thread
 
LinkBack Thread Tools
Old 04-22-2010, 02: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 02:56 AM.
Offline  
Old 04-22-2010, 08: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, 08: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, 10: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





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