0

SSO 認証されたサーバーで認証済み URL を呼び出したい。このために、HTTPClient へのリクエストにある Cookie に対処しています。以下のコードは正常に動作します。

    def cookies = []
    request.getCookies().each {
        def cookie = new BasicClientCookie(it.name, it.value)
        cookie['domain'] = it.domain
        cookie['path'] = it.path
        cookie.secure = true
        cookies.add(cookie)
    }

   // **** Setting cookies using header *****
   def output = withHttp(uri: "https://testserver.com") {
        def builder = delegate;

        def html = get(path : '/testactoin.do', 
            headers:['Cookie':cookies.collect{it.name+"="+it.value}.join("; ")],
            contentType : ContentType.XML, 
            query : 
            [
                query: params.query,
                count: params.count,
                cacheName: 'contentStoreCityState',
                filterString: 'address.country=CA,GB,US'
            ]
        )
        return html
    }

ただし、API を使用して Cookie を設定しようとすると、機能しません。以下のコード スニペットを参照してください。

def cookies = []
request.getCookies().each {
    def cookie = new BasicClientCookie(it.name, it.value)
    cookie['domain'] = it.domain
    cookie['path'] = it.path
    cookie.secure = true
    cookies.add(cookie)
}

def output = withHttp(uri: "https://testserver.com") {
    def builder = delegate;

    // **** Setting cookies using api call *****
    cookies.each {
       builder.client.cookieStore.addCookie(it)
    }

    def html = get(path : '/testactoin.do', 
        contentType : ContentType.XML, 
        query : 
        [
            query: params.query,
            count: params.count,
            cacheName: 'contentStoreCityState',
            filterString: 'address.country=CA,GB,US'
        ]
    )
    return html
}

addCookie メソッドを使用して Cookie を設定する際の問題は何ですか? 例外も警告メッセージも生成しません。

4

1 に答える 1

0

最初のコード スニペットでは Cookie を設定していますが、ヘッダーは実際には Set-Cookie です。

于 2013-08-08T14:17:01.640 に答える