ALM 12:通过 REST returns 400 错误请求进行身份验证

ALM 12: Authentication via REST returns 400 bad request

我遵循此处的指导:http://alm-help.saas.hp.com/en/12.50/api_refs/REST_TECH_PREVIEW/Content/General/Session_Management.html

我将以下请求发送至 alm12.test。com/qcbin/authentication-point/alm-authenticate

Headers:

Content-Type: application/xml Accept: application/xml

请求

<?xml version='1.0' encoding='utf-8'?><alm-authentication><user>userxy</user><password>yyy</password></alm-authentication>

这会导致以下响应 (LWSSO_COOKIE_KEY): Content-Length: 0 Date: Mon, 02 May 2016 13:28:00 GMT Set-Cookie: LWSSO_COOKIE_KEY=o1MfQIVWQg2x09CKUlkqARQsRHAhvADYsKhl4AM2ARiJpJesV_fA6xVeYbm4ek1CPdbmmsOGMaCORTsOmHMJVa3V5JKQLIywiubZQQtFfV15PS82qj4bRJ6mhmGqZU6XU8DMPLYuSLfRjfjLrxtix6cMHD1JpdlYHhTxfbo5No62s36Hw8UH12lZlrGzPfY_EFJE8k28TPqflXJQccdHErbCG8.;Path=/;HTTPOnly Server: Jetty(7.5.4.v20111024)

否,我向 alm12.test 发送请求。com/qcbin/rest/site-session 打开一个 session Header Content-Type: application/xml Accept: application/xml Cookie: LWSSO_COOKIE_KEY=o1MfQIVWQg2x09CKUlkqARQsRHAhvADYsKhl4AM2ARiJpJesV_fA6xVeYbm4ek1CPdbmmsOGMaCORTsOmHMJVa3V5JKQLIywiubZQQtFfV15PS82qj4bRJ6mhmGqZU6XU8DMPLYuSLfRjfjLrxtix6cMHD1JpdlYHhTxfbo5No62s36Hw8UH12lZlrGzPfY_EFJE8k28TPqflXJQccdHErbCG8.;Path=/;HTTPOnly

不幸的是,我收到错误代码 400 - 错误请求。

我做错了什么?

您传递的 cookie 值似乎不正确。

应该是

LWSSO_COOKIE_KEY=oPGiBQVkwhZ4uThtZj1MfQIVWQg2x09CKUlkqARQsRHAhvADYsKhl4AM2ARiJpJesV_fA6xVeYbm4ek1CPdbmmsOGMaCORTsOmHMJVa3V5JKQLIywiubZQQtFfV15PS82qj4bRJ6mhmGqZU6XU8DMPLYuSLfRjfjLrxtix6cMHD1JpdlYHhTxfbo5No62s36Hw8UH12lZlrGzPfY_EFJE8k28TPqflXJQccdHErbCG8

不包括 ;Path=/;HTTPOnly

这是 Python 实现:

第一个 POST 请求(LWSSO_COOKIE_KEY) 第二个 POST 请求 ( QCSession )

self.headers = {}
response = requests.post(self.auth_endpoint, auth=HTTPBasicAuth(self.user_name, self.password),
                                 headers=self.headers)
        if response.status_code == 200:
            cookieName = response.headers.get('Set-Cookie')
            LWSSO_COOKIE_KEY = cookieName[cookieName.index("=") + 1: cookieName.index(";")]
            self.cookies['LWSSO_COOKIE_KEY'] = LWSSO_COOKIE_KEY
        response = requests.post(self.qc_session_endpoint, headers=self.headers, cookies=self.cookies)
        if response.status_code == 200 | response.status_code == 201:
            cookieName = response.headers.get('Set-Cookie').split(",")[1]
            QCSession = cookieName[cookieName.index("=") + 1: cookieName.index(";")]
            self.cookies['QCSession'] = QCSession

我遇到了同样的错误,删除以下内容后一切正常。

Type: application/xml Accept: application/xml

所以你的请求应该只有 LWSSO_COOKIE_KEY cookie 而没有任何其他 headers