简体   繁体   English

Apache Commons HttpClient PostMethod 支持?

[英]Apache Commons HttpClient PostMethod support?

I am curios about how one can set the request properties for a PostMethod in Apache Commons HttpClient?我很好奇如何在 Apache Commons HttpClient 中设置 PostMethod 的请求属性?

I am refactoring some code written using HttpURLConnection class to post which looks like the following:我正在重构一些使用 HttpURLConnection class 编写的代码以发布如下所示:

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? 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 -亚历克斯

Those are both request headers, so you would need to call setRequestHeader() to establish those values on the connection.这些都是请求标头,因此您需要调用 setRequestHeader() 来在连接上建立这些值。 HttpClient also supports handling basic authentication so the "Authorization" header can be refactored out, depending on how deep your changes go. HttpClient 还支持处理基本身份验证,因此可以重构“授权”header,具体取决于更改 go 的深度。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM