java—如何在robot框架中将http客户端响应转换为字典

j9per5c4  于 2021-09-13  发布在  Java
关注(0)|答案(1)|浏览(257)

我正在点击一个url并获取作为响应数据的数据。我想将此响应转换为dictionary,但它给出了以下错误类型error:'com.github.hi_fi.httpclient.domain.responsedata'对象不可编辑我想将响应转换为dictionary以从响应中获取id值
代码:

Create Session  httpbin   ${testServer}    debug=True
    Set Test Variable  &{headers}  Authorization=${Token}
    &{data}=  Create Dictionary  name=robot  gender=male  email=robot64@gmail  status=Active

    ${resp}=  Post Request   httpbin   /public/v1/users   ${data}  headers=${headers}
    log   ${resp}

    &{dit}=  Convert to Dictionary  ${resp}  //Fails 
    log  &{dit}

我可以通过${responseid}=find json元素${resp}$..id获取id
响应:在此处输入图像描述

eaf3rand

eaf3rand1#

请求图书馆/ Post Request 返回响应对象(例如头、请求本身、其他属性),而不仅仅是有效负载字符串。因此,它无法转换为dict。
您可以使用 ${resp.content} ,或者如果您确定它是一个json,您可以使用 ${resp.json()} .

相关问题