目前我正在开发一个Java工具,它应该可以更新Confluence服务器页面。使用Curl一切都像一个符咒,但是当使用Postman或Java代码(HttpClient Java11)时,我得到了一个
HTTP状态401–未经授权
反应。
在下面的语句中使用curl
curl--basic-u user:password-X PUT-H“内容类型:application/json”-d“@test.json”https://confluence.xxx.com/confluence/rest/api/content/{pageID}
它工作得很好。
以下Java代码:
String encode = Base64.getEncoder().encodeToString((confluence_username + ":" + confluence_password).getBytes());
HttpClient client = HttpClient.newHttpClient();
HttpRequest request = HttpRequest.newBuilder()
.uri(URI.create(endpoint))
.header("Authorization", "Basic " + encode)
.header("Content-Type", "application/json")
.PUT(HttpRequest.BodyPublishers.ofString(inputJson))
.build();
HttpResponse<String> response = client.send(request, HttpResponse.BodyHandlers.ofString());
System.out.println(response.statusCode());
System.out.println(response.body());
“endpoint”是Confluence页面URI,给出401响应。
在邮递员中,回应总是401。
我重新检查了登录详细信息,它们100%正确。此外,在运行程序/邮递员之前,我检查了帐户是否需要验证码刷新。
GET https://confluence.xxx.com/confluence/rest/api/content/xxx: {
"Network": {
"addresses": {
"local": {
"address": "1.2.3.4",
"family": "IPv4",
"port": 50668
},
"remote": {
"address": "1.2.3.4",
"family": "IPv4",
"port": 443
}
},
"tls": {
"reused": true,
"authorized": true,
"authorizationError": null,
"cipher": {
"name": "XXXX",
"standardName": "TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384",
"version": "TLSv1/SSLv3"
},
"protocol": "TLSv1.2",
"ephemeralKeyInfo": {},
"peerCertificate": {
"subject": {
"country": "X",
"stateOrProvince": "X",
"locality": "X",
"organization": "X",
"organizationalUnit": "X",
"commonName": "X",
"alternativeNames": "X, X"
},
"issuer": {
"country": "X",
"organization": "X",
"commonName": "X"
},
"validFrom": "Mar 6 10:34:33 2020 GMT",
"validTo": "Mar 6 10:44:00 2022 GMT",
"fingerprint": "X",
"serialNumber": "X"
}
}
},
"Request Headers": {
"x-atlassian-token": "no-check",
"content-type": "application/json",
"authorization": "Basic XXX",
"user-agent": "PostmanRuntime/7.28.3",
"accept": "*/*",
"postman-token": "42958f39-7fad-4e37-b2d1-657343e45403",
"host": "confluence.XXX.com",
"accept-encoding": "gzip, deflate, br",
"connection": "keep-alive",
"cookie": "JSESSIONID=1DSF345jl3h45kD82"
},
"Request Body": "",
"Response Headers": {
"date": "Wed, 11 Aug 2021 06:36:28 GMT",
"server": "Apache/2.4.6 (Red Hat Enterprise Linux) OpenSSL/1.0.2k-fips",
"x-asen": "SEN-4272739",
"x-seraph-loginreason": "AUTHENTICATION_DENIED",
"www-authenticate": "OAuth realm=\"https%3A%2F%2Fconfluence.xxx.com%2Fconfluence\"",
"content-type": "text/html;charset=utf-8",
"content-language": "en",
"content-length": "437",
"keep-alive": "timeout=5, max=100",
"connection": "Keep-Alive",
"strict-transport-security": "max-age=31536000"
},
"Response Body": "<!doctype html><html lang=\"en\"><head><title>HTTP Status 401 – Unauthorized</title><style type=\"text/css\">body {font-family:Tahoma,Arial,sans-serif;} h1, h2, h3, b {color:white;background-color:#525D76;} h1 {font-size:22px;} h2 {font-size:16px;} h3 {font-size:14px;} p {font-size:12px;} a {color:black;} .line {height:1px;background-color:#525D76;border:none;}</style></head><body><h1>HTTP Status 401 – Unauthorized</h1></body></html>"
}
谢谢你的帮助!
看起来像是用邮递员发出HTTPS请求的问题。确保你已经禁用了邮递员中的HTTPS。
邮差
有关更多详细信息:使用post发送带有HTTPS请求的证书
问题内容: 从HttpClient 4.3开始,我一直在使用HttpClientBuilder。我正在连接到具有基本身份验证的REST服务。我将凭据设置如下: 但是,这不起作用(我正在使用的REST服务返回401)。怎么了? 问题答案: 从此处的 抢先身份验证 文档中: http://hc.apache.org/httpcomponents-client- ga/tutorial/html/aut
几天没有任何进展,我需要你的帮助。 使用GWT,我试图与REST服务器通信,服务器位于不同的URL上(需要CORS)<我的配置:服务器spring boot 1.3.3 客户端-GWT 1.7-restygwt 2.0.3 当我在Spring中禁用安全性时,我可以在我的GWT客户端中获取数据。 但是当我启用它时,我总是收到401个请求。REST URL请求直接在Web浏览器中工作(带有其身份验证对
我正在尝试使用OAuth2实现开发一个带有Spring Security性的rest api。但是如何删除基本身份验证呢。我只想向body发送用户名和密码,并在postman上获取令牌。 要删除基本身份验证,并从邮递员的get token中发送body标记中的用户名密码吗 我遇到了一些问题{"错误":"未经授权","error_description":"没有客户端身份验证。尝试添加适当的身份验证
我尝试了angular.js,并从一个restful api的web-ui开始(使用超文本传输协议基本授权)。这真的很好,除了授权工作。 到目前为止,我使用的是设置密码,但大多数情况下浏览器会打开http basic auth的默认登录表单。另一个奇怪的行为是angular请求不包含授权头(选项和GET请求都不包含)。我还尝试使用header配置在每个请求上设置此header,但这也不起作用。 有
我有一个基本的SOAP服务endpoint,实际上是SAP ECC,它表示一个服务。我已经使用SOAPUI4.5测试了该服务,使用HTTPAuth可以正常工作,可以根据事物的外观进行抢占。我看到一个出站“Authorization:Basic BASE64”,服务会做出相应响应。 我现在正试图将其引入Java。我想我会采取SAAJ方法: 但我无法在中添加HTTP身份验证。我相信SAAJ提供了控制S
但我对spring-boot/java还是个新手...有谁能帮我把这条路走对吗? 多谢了。