POST 请求 Content-Type application/x-www-form-urlencoded 和

POST request with Content-Type application/x-www-form-urlencoded and

我的要求很简单

使用 ID 和密码调用 POST 请求。 Header 有 Content-Type = application/x-www-form-urlencoded 并且数据也作为 urlencoded 传递,如下所示

响应将以 xml 格式出现。

我尝试了很多来自各地的示例,但似乎没有任何效果。它返回 401 Unauthorized,这是目标 API 在请求格式不正确时抛出的错误。

http://zetcode.com/java/getpostrequest/

正是我所需要的。 Java 页面上带有 HttpURLConnection 部分的 HTTP POST 请求完成了工作。