黑莓 HTTP POST 问题
我在从黑莓发送 POST 到服务器时遇到问题(我目前在模拟器上尝试)。问题是,POST 数据未发送到服务器。
我知道有很多关于此的主题,但我尝试了很多,但仍然无法使其发挥作用。
这是我在黑莓中使用的代码
hc = (HttpConnection)Connector.open(Params.URL_TTS_GET, Connector.READ_WRITE);
//Prepare post
URLEncodedPostData p = new URLEncodedPostData(URLEncodedPostData.DEFAULT_CHARSET, false);
p.append("ttsid", "" + header.id);
byte[] data = p.getBytes();
String ss = new String(data);
hc.setRequestMethod(HttpConnection.POST);
hc.setRequestProperty(HttpProtocolConstants.HEADER_CONTENT_TYPE, p.getContentType());
hc.setRequestProperty(HttpProtocolConstants.HEADER_CONTENT_LENGTH, Integer.toString(data.length));
OutputStream os = hc.openOutputStream();
os.write(data);
os.close();
我也尝试过:
ConnectionFactory cf = new ConnectionFactory();
hc = (HttpConnection)cf.getConnection(Params.URL_TTS_GET).getConnection();
但由于未知原因收到 301(永久移动)响应。
任何帮助将非常感激:)
I have a problem with sending POST to server from blackberry (I currently trying on simulator). The problem is, the POST data isn't send to server.
I know there are lot of topics about this, but I'va tried many of them but still I can't make it work.
Here is the code I use in the blackberry
hc = (HttpConnection)Connector.open(Params.URL_TTS_GET, Connector.READ_WRITE);
//Prepare post
URLEncodedPostData p = new URLEncodedPostData(URLEncodedPostData.DEFAULT_CHARSET, false);
p.append("ttsid", "" + header.id);
byte[] data = p.getBytes();
String ss = new String(data);
hc.setRequestMethod(HttpConnection.POST);
hc.setRequestProperty(HttpProtocolConstants.HEADER_CONTENT_TYPE, p.getContentType());
hc.setRequestProperty(HttpProtocolConstants.HEADER_CONTENT_LENGTH, Integer.toString(data.length));
OutputStream os = hc.openOutputStream();
os.write(data);
os.close();
I also tried this :
ConnectionFactory cf = new ConnectionFactory();
hc = (HttpConnection)cf.getConnection(Params.URL_TTS_GET).getConnection();
But got 301 (Moved permanently) response for unknown reason.
any help will be very appreciated :)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论