我正在使用HttpClient开发一个Java工具,以编程方式将VuGen脚本上传到Performance Center。我的工具是做什么的:
验证和注销步骤正常运行。也就是说,我可以从身份验证中获取会话cookie,并在注销时将cookie设置为过期。但是,在上传脚本步骤中,我总是收到HTTP 401错误。这是一条错误消息:
401 - 未经授权:由于凭据无效,访问被拒绝。
您无权使用以下方式查看此目录或页面 您提供的凭据。
这是我发送给Performance Center服务器的内容。
POST http://[PC-Host]/LoadTest/rest/domains/[MyDomain]/projects/[MyProject]/Scripts HTTP/1.1
Content-Type: multipart/form-data
Content-Length: 31367
Host: [PC-Server]
Connection: Keep-Alive
User-Agent: Apache-HttpClient/4.5.2 (Java/1.8.0_111)
Cookie: LWSSO_COOKIE_KEY=1y8TbNawvT976BENi4oT1hW6_dCMwcz-eohdFDqWpfIXsW2tUMYHZuHZbUBg9wFQwFnQgfetx5I2EvCfaA5y-g..; QCSession=NjA3NTY5O0JWK0ZjSExzWStwTFZPd2xZSXZ5VlEqKjtQQyBSRVNUIEFQSSBDbGllbnQ7IDsg
Accept-Encoding: gzip,deflate
--_NK2aWTiwhT6VV0TIxkUIaHRx0GhDBZ2LOsY8
Content-Disposition: form-data; name="xml"
Content-Type: application/xml; charset=ISO-8859-1
Content-Transfer-Encoding: 8bit
<Script xmlns="http://www.hp.com/PC/REST/API"><TestFolderPath>Subject\DEV\abc</TestFolderPath><Overwrite>true</Overwrite><RuntimeOnly>true</RuntimeOnly><KeepCheckedOut/></Script>
--_NK2aWTiwhT6VV0TIxkUIaHRx0GhDBZ2LOsY8
Content-Disposition: form-data; name="file"; filename="abc.zip"
Content-Type: application/octet-stream
Content-Transfer-Encoding: binary
## binary of zipped vugen script ##
--_NK2aWTiwhT6VV0TIxkUIaHRx0GhDBZ2LOsY8--
我不知道我做错了什么。你有什么想法吗?
答案 0 :(得分:0)
Problem solved. XML encoding was to to blame. I also moved to requests toolbelt to have more control on the multipart structure.