我将以下请求发送至alm12.test.com/qcbin/authentication-point/alm-authenticate
接头
Content-Type: application/xml
Accept: application/xml
请求
<?xml version='1.0' encoding='utf-8'?><alm-authentication><user>userxy</user><password>yyy</password></alm-authentication>
导致以下repsonse(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打开会话
标题
Content-Type: application/xml
Accept: application/xml
Cookie: LWSSO_COOKIE_KEY=o1MfQIVWQg2x09CKUlkqARQsRHAhvADYsKhl4AM2ARiJpJesV_fA6xVeYbm4ek1CPdbmmsOGMaCORTsOmHMJVa3V5JKQLIywiubZQQtFfV15PS82qj4bRJ6mhmGqZU6XU8DMPLYuSLfRjfjLrxtix6cMHD1JpdlYHhTxfbo5No62s36Hw8UH12lZlrGzPfY_EFJE8k28TPqflXJQccdHErbCG8.;Path=/;HTTPOnly
不幸的是,我只收到错误代码400 - 错误请求。
我做错了什么?
答案 0 :(得分:0)
您传递的Cookie值似乎不正确。
应该是 LWSSO_COOKIE_KEY = oPGiBQVkwhZ4uThtZj1MfQIVWQg2x09CKUlkqARQsRHAhvADYsKhl4AM2ARiJpJesV_fA6xVeYbm4ek1CPdbmmsOGMaCORTsOmHMJVa3V5JKQLIywiubZQQtFfV15PS82qj4bRJ6mhmGqZU6XU8DMPLYuSLfRjfjLrxtix6cMHD1JpdlYHhTxfbo5No62s36Hw8UH12lZlrGzPfY_EFJE8k28TPqflXJQccdHErbCG8。
不要包含;路径= /; HTTPOnly
答案 1 :(得分:0)
以下是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
答案 2 :(得分:0)
删除以下内容后,我遇到了相同的错误。
Type: application/xml
Accept: application/xml
因此,您的请求应仅包含LWSSO_COOKIE_KEY
cookie,没有其他任何标头