【问题标题】:What sessionid/cookie information does asmx expect in the header?asmx 在标头中期望什么 sessionid/cookie 信息?
【发布时间】:2012-12-16 00:04:52
【问题描述】:

我在调用登录 webmethod 时保存了 http 标头 cookie/sessionid 信息,因此我可以在随后的由 formsauthentication 保护的 webmethod 调用中将其发回。我想我只需要知道正确的标头值即可保存并将它们发回。

我正在使用 ksoap2 从一个 android 应用程序调用这些服务。

当我在调用登录时单步执行代码时。我看到 两个 Set-Cookie 标题项:

Set-Cookie
ASP.NET_SessionId=wblzzrtfmli4blku2dslw5iw; path=/; HttpOnly

Set-Cookie
.ASPXAUTH=8264E023428DA853BB163504C0D375D792FC631BB873F04D196E04BAEDE7F7BB39BB5C840D0CD0613A0DD58B2456F12EE21F212D93457F3D6BC2FC343C6AE1E3DD97473B055B36379D178FE6C412EFF61CFCE7FACAF43EEAE85C46B5123CB97C3AFF156F54921993F4A2B85BEE239EAFB05AFFF58FBDA3B7EBDC59B5E0A614D8CC086B5C7DF3A884DE95DBE05F6A138DB97241666870AAF9320EDD; path=/; HttpOnly

正如我从documentation hereanswer here 中了解到的,我必须使用CookieSet-Cookie 值返回给后续的webmethods。但正如您在上面看到的,我得到了 TWO Set-Cookie 标题项。那么我应该发回哪个,我可以按原样发回还是需要去掉.ASPXAUTH= 部分或其他任何内容?

【问题讨论】:

    标签: android forms-authentication asmx ksoap2 android-ksoap2


    【解决方案1】:

    当我在我的 Web 应用程序中从 JQuery Ajax 调用安全服务时,我能够通过嗅探 Set-Cookie 标头的外观来得到答案。

    基本上,我使用分号“;”连接了两个 Set-Cookie 值。

    在登录时我是这样保存的:

    StringBuilder cookieBuilder = new StringBuilder();
    
    int intCookieValueCount = 0;
    for (Object header : headerList) {
        HeaderProperty headerProperty = (HeaderProperty) header;
        String headerKey = headerProperty.getKey();
        String headerValue = headerProperty.getValue();
    
        if(headerKey != null){
            if(headerKey.equals("Set-Cookie"))
            {
                if(intCookieValueCount!=0){
                    cookieBuilder.append("; ");
                }                   
                cookieBuilder.append(headerValue);
                intCookieValueCount++;
            }                   
        }
    }
    
    AppSettings.setSessionCookie(cookieBuilder.toString());
    

    在后续调用中:

    HeaderProperty headerPropertyObj = new HeaderProperty("Cookie", AppSettings.getSessionCookie());
    @SuppressWarnings("rawtypes")
    List headerList = new ArrayList();
    
    headerList.add(headerPropertyObj);
    
    androidHttpTransport.call(SOAP_ACTION, envelope, headerList); 
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-01-31
      • 2013-05-13
      • 1970-01-01
      • 1970-01-01
      • 2013-12-22
      • 1970-01-01
      相关资源
      最近更新 更多