我们如何通过GET方法发送数据?
我正在创建 HTTPS 连接并将请求属性设置为 GET:
_httpsConnection = (HttpsConnection) Connector.open(URL, Connector.READ_WRITE);
_httpsConnection.setRequestMethod(HttpsConnection.GET);
但是如何发送 GET 参数? 我是否像这样设置请求属性:
_httpsConnection.setRequestProperty("method", "session.getToken");
_httpsConnection.setRequestProperty("developerKey", "value");
_httpsConnection.setRequestProperty("clientID", "value");
或者我是否必须写入连接的输出流?
或者我是否需要通过将参数/值附加到 url 来发送参数/值?
I am creating a HTTPS connection and setting the request property as GET:
_httpsConnection = (HttpsConnection) Connector.open(URL, Connector.READ_WRITE);
_httpsConnection.setRequestMethod(HttpsConnection.GET);
But how do I send the GET parameters?
Do I set the request property like this:
_httpsConnection.setRequestProperty("method", "session.getToken");
_httpsConnection.setRequestProperty("developerKey", "value");
_httpsConnection.setRequestProperty("clientID", "value");
or do I have to write to the output stream of the connection?
or do I need to send the Parameter/Values by appending it to the url?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
调用
Connection.setRequestProperty()
将设置请求标头,在这种情况下,这可能不是您想要做的(如果您问我,我认为调用它 setRequestHeader 会是一个更好的选择)。某些代理可能会删除或重写非标准标头的名称,因此您最好坚持通过 URL 参数在 GET URL 中传递数据的约定。在 BlackBerry 上执行此操作的最佳方法是使用
URLEncodedPostData
类对 URL 参数进行正确编码:Calling
Connection.setRequestProperty()
will set the request header, which probably isn't what you want to do in this case (if you ask me I think calling it setRequestHeader would have been a better choice). Some proxies may strip off or rewrite the name of non-standard headers, so you're better off sticking to the convention of passing data in the GET URL via URL parameters.The best way to do this on a BlackBerry is to use the
URLEncodedPostData
class to properly encode your URL parameters:HTTP GET
将数据参数作为 URL 中编码的键/值对发送,就像:注意遵循字符分隔符规则:
您必须了解特定于平台的本机字符串编码函数。 Javascript 使用
escape
,C# 使用HttpUtility.UrlEncode
HTTP GET
send data parameters as key/value pairs encoded within URL, just like:Note follow rules for character separators:
You must know your platform specific native string encode function. Javascript uses
escape
, C# usesHttpUtility.UrlEncode
是的,标头和属性几乎就是您可以在 GET 中发送的所有内容。另外,您只能使用一定数量的字符,这取决于浏览器 - 我记得通常大约是 1024 或 2000 个。
Yep, headers and properties are pretty much all you can send in a GET. Also, you're limited to a certain number of characters, which is browser dependent - I seem to recall about 1024 or 2000, typically.