Jersey Client: Adding Cookies to Request

前端 未结 4 1165
我寻月下人不归
我寻月下人不归 2020-12-05 08:07

I am trying to write a library that accesses a RESTful web service using the Jersey Client API. The service requires a login request that sets a cookie, then subsequent req

4条回答
  •  自闭症患者
    2020-12-05 08:45

    Perhaps you need to fit cookies into a WebResource call that had been working previously without them. Then you might find yourself breaking up your line of code that you can work with the builder part way through. To include cookies, your code might go from:

    clientResponse =   webResource.queryParams(parameters).type(httpContentType).accept(httpAcceptType).post(ClientResponse.class, requestBody);
    

    To:

    builder = webResource.queryParams(parameters).type(httpContentType);
    if (cookieJar != null)
    {
        for (Cookie c : cookieJar)
            builder = builder.cookie(c);
    }
    clientResponse = builder.accept(httpAcceptType).post(ClientResponse.class, requestBody);
    

提交回复
热议问题