开发者

j2me multiple cookies

how to read http multiple responce headers with the same key name like set-cookie from j2me httpconnection? (looping through headers with getHeaderF开发者_运维问答ield(int i) also did not solve the problem). because of this problam i tried to rewite my own http client on a socket connection. but jsr-185 does not allow sockets to port 80, 8080 and 443. to use them application should be signed.


Looping through headers with getHeaderField(int i) works for me in WTK emulator. IMHO, some devices can have this bug non-fixed: http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4634244


The problem can be solved like this. In the code below we are extracting "JSESSION" and "SOME_COOKIE", two cookies coming from a server that is using the same header "set-cookie".

String sessionID = "";
String someCookie = "";
String headerKey = "";
int indexField = 0;
while((headerKey = httpConnection.getHeaderFieldKey(indexField)) != null){
    String headerValue = httpConnection.getHeaderField(indexField);
    if(headerKey.equals("set-cookie")){
        //do something with the string
        if(headerValue.indexOf("JSESSION")>=0){//if "JSESSION" is present in the String
            sessionID = headerValue.substring(0, headerValue.indexOf(";"));
        }
        if(headerValue.indexOf("SOME_COOKIE")>=0){//if "SOME_COOKIE" is present in the String
            someCookie = headerValue.substring(0, headerValue.indexOf(";"));
        }
    }
    indexField++;
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜