c - how to get cookies id from HTTP header using libcurl -
the http haeder of server :
server: apache-coyote/1.1 set-cookie: jsessionid=72d8dc23bd37016cd5557bb353dd008e; path=/tt/; httponly soapaction: content-type: text/xml;charset=iso-8859-1 content-length: 491 date: wed, 03 jun 2015 14:02:53 gmt
how cookies id "jsessionid=72d8dc23bd37016cd5557bb353dd008e" , using http client.
i used these functions init http header , send msg :
int http_client_init(struct cmp *cmp) { #ifdef http_curl http_c.header_list = null; http_c.header_list = curl_slist_append(http_c.header_list, "user-agent: cmp"); if (!http_c.header_list) return -1; http_c.header_list = curl_slist_append(http_c.header_list, "content-type: text/xml"); if (!http_c.header_list) return -1; # ifdef acs_fusion char *expect_header = "expect:"; http_c.header_list = curl_slist_append(http_c.header_list, expect_header); if (!http_c.header_list) return -1; # endif /* acs_fusion */ curl = curl_easy_init(); if (!curl) return -1; #endif /* http_curl */ #ifdef http_zstream http_c.stream = zstream_open(http_c.url, zstream_post); if (!http_c.stream) return -1; # ifdef acs_hdm if (zstream_http_configure(http_c.stream, zstream_http_cookies, 1)) # elif acs_multi if (zstream_http_configure(http_c.stream, zstream_http_cookies, 3)) # endif return -1; if (zstream_http_addheader(http_c.stream, "user-agent", "cmp")) return -1; if (zstream_http_addheader(http_c.stream, "content-type", "text/xml")) return -1; #endif /* http_zstream */ return 0; } int http_send_message(struct cmp *cmp, char *msg_out, char **msg_in) { #ifdef http_curl curlcode res; long http_code = 0; static char *ip_acs = null; char *ip = null; curl_easy_setopt(curl, curlopt_url, http_c.url); curl_easy_setopt(curl, curlopt_username, cmp->conf.acs_userid); curl_easy_setopt(curl, curlopt_password, cmp->conf.acs_passwd); curl_easy_setopt(curl, curlopt_httpauth, curlauth_basic|curlauth_digest); curl_easy_setopt(curl, curlopt_httpheader, http_c.header_list); curl_easy_setopt(curl, curlopt_timeout, http_timeout); curl_easy_setopt(curl, curlopt_connecttimeout, http_timeout); curl_easy_setopt(curl, curlopt_followlocation, 1l); curl_easy_setopt(curl, curlopt_cookiefile, fc_cookies); curl_easy_setopt(curl, curlopt_cookiejar, fc_cookies); curl_easy_setopt(curl, curlopt_postfields, msg_out); if (msg_out) curl_easy_setopt(curl, curlopt_postfieldsize, (long) strlen(msg_out)); else curl_easy_setopt(curl, curlopt_postfieldsize, 0); curl_easy_setopt(curl, curlopt_writefunction, http_get_response); curl_easy_setopt(curl, curlopt_writedata, msg_in); # ifdef devel curl_easy_setopt(curl, curlopt_verbose, 1l); # endif *msg_in = (char *) calloc (1, sizeof(char)); res = curl_easy_perform(curl); if (!strlen(*msg_in)) free(*msg_in); curl_easy_getinfo(curl, curlinfo_primary_ip, &ip); if (ip) { if (!ip_acs || strcmp(ip_acs, ip) != 0) { free(ip_acs); ip_acs = strdup(ip); external_simple("allow_cr_ip", ip_acs); } } curl_easy_getinfo(curl, curlinfo_response_code, &http_code); if(http_code == 204) { cmp_log (info,"receive http 204 no content"); } if (http_code != 200 && http_code != 204) goto error; curl_easy_reset(curl); if (res) goto error; #endif /* http_curl */ #ifdef http_zstream char buffer[bufsiz]; ssize_t rxed; if (zstream_reopen(http_c.stream, http_c.url, zstream_post)) { /* not good, let's try recreate */ http_client_exit(); if (http_client_init(cmp)) return -1; } if (msg_out) { zstream_write(http_c.stream, msg_out, strlen(msg_out)); } else { zstream_write(http_c.stream, null , 0); } *msg_in = (char *) calloc (1, sizeof(char)); while ((rxed = zstream_read(http_c.stream, buffer, sizeof(buffer))) > 0) { *msg_in = (char *) realloc(*msg_in, (strlen(*msg_in) + rxed + 1) * sizeof(char)); if (!(*msg_in)) return -1; bzero(*msg_in + strlen(*msg_in), rxed + 1); memcpy(*msg_in + strlen(*msg_in), buffer, rxed); } /* got no response, ok , defined in documentation */ if (!strlen(*msg_in)) { free(*msg_in); } if (rxed < 0) goto error; #endif /* http_zstream */ return 0; error: free(*msg_in); return -1; }
to set cookies option http client doesn't take cookies id http header of server communication between client , server broken
any appreciated
Comments
Post a Comment