2011-09-21 107 views
1

我想在我的黑莓应用程序中设置一个http文章。我已经在我的相应Android应用程序中成功实现了这个功能,所以我知道它工作的服务器找到了。我尝试了几个不同的东西,而且我没有真正得到错误,它只是在服务器上的信息没有得到更新。我看过这个帖子: Http POST in BlackBerry,和其他几个。我发现他们很有帮助,但他们并没有最终解决我的问题。再次,我没有得到错误,但服务器没有得到更新。这里是我目前使用的代码:http post与黑莓

String url = "http://xxxx.com/ratings/add?;deviceside=true"; 
String postStr1 = "business_id=790"; 
String postStr2 = "&rating=4"; 

HttpConnection httpConnection = (HttpConnection) Connector.open(url); 
httpConnection.setRequestMethod(HttpConnection.POST); 
httpConnection.setRequestProperty("Content-Type", "application/x-www-form-urlencoded"); 

URLEncodedPostData encPostData = new URLEncodedPostData("UTF-8", false); 
encPostData.append("business_id", String.valueOf(790)); 
encPostData.append("rating", String.valueOf(4)); 
byte[] postData = encPostData.toString().getBytes("UTF-8"); 

httpConnection.setRequestProperty("Content-Length", String.valueOf(postData.length)); 

OutputStream os = httpConnection.openOutputStream(); 
os.write(postData); 
os.flush(); 

任何人有什么想法可能是错的?

+2

如果您调用httpConnection.getResponseMessage(),会得到什么信息? – Jonathan

+0

你可能想看看这个:http://stackoverflow.com/questions/7455891/j2me-app-not-sending-post-requests –

+0

我得到:暂时移动......这是什么意思? – coder

回答

1

有几件事情正在进行。首先,我的模拟器没有正确连接到互联网。一旦得到了理顺,我删除了

deviceside=true 
从我的网址

,现在它的伟大工程。谢谢大家!