Apache Commons HttpClient PostMethod 支持吗?
我很好奇如何在 Apache Commons HttpClient 中设置 PostMethod 的请求属性?
我正在重构一些使用 HttpURLConnection 类编写的代码来发布,如下所示:
conn1.setRequestProperty(
"Content-Type", "multipart/related; type=\"application/xml\"; boundary="
+ boundary);
conn1.setRequestProperty("Authorization", auth);
... ...
使用:
PostMethod method = new PostMethod(_Server);
method.setRequestBody(...); or
method.setRequestHeader(...);
但我不确定这是否/如何映射到我想要对原始 URL 类执行的操作...任何人都可以帮助澄清如何使用 PostMethod 类设置请求属性?
多谢!
-亚历克斯
I am curios about how one can set the request properties for a PostMethod in Apache Commons HttpClient?
I am refactoring some code written using HttpURLConnection class to post which looks like the following:
conn1.setRequestProperty(
"Content-Type", "multipart/related; type=\"application/xml\"; boundary="
+ boundary);
conn1.setRequestProperty("Authorization", auth);
... ...
To use:
PostMethod method = new PostMethod(_Server);
method.setRequestBody(...); or
method.setRequestHeader(...);
But i am not sure if / how this will map to what i want to do with the original URL class... can anyone help clarify how to set request properties with PostMethod class?
Thanks a lot!
-alex
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这些都是请求标头,因此您需要调用 setRequestHeader() 在连接上建立这些值。 HttpClient 还支持处理基本身份验证,因此可以重构“Authorization”标头,具体取决于更改的深度。
Those are both request headers, so you would need to call setRequestHeader() to establish those values on the connection. HttpClient also supports handling basic authentication so the "Authorization" header can be refactored out, depending on how deep your changes go.