/*-------------------------------------------------- FUNCTION: httpc_post_begin DESC: Returns H_OK if success ----------------------------------------------------*/ herror_t httpc_post_begin(httpc_conn_t * conn, const char *url) { herror_t status; if ((status = httpc_talk_to_server(HTTP_REQUEST_POST, conn, url)) != H_OK) return status; conn->out = http_output_stream_new(&(conn->sock), conn->header); return H_OK; }
herror_t httpd_send_header(httpd_conn_t * res, int code, const char *text) { struct tm stm; time_t nw; char buffer[255]; char header[1024]; hpair_t *cur; herror_t status; /* set status code */ sprintf(header, "HTTP/1.1 %d %s\r\n", code, text); /* set date */ nw = time(NULL); localtime_r(&nw, &stm); strftime(buffer, 255, "Date: %a, %d %b %Y %H:%M:%S GMT\r\n", &stm); strcat(header, buffer); /* set content-type */ /* * if (res->content_type[0] == '\0') { strcat(header, "Content-Type: * text/html\r\n"); } else { sprintf(buffer, "Content-Type: %s\r\n", * res->content_type); strcat(header, buffer); } */ /* set server name */ strcat(header, "Server: nanoHTTP library\r\n"); /* set _httpd_connection status */ /* strcat (header, "Connection: close\r\n"); */ /* add pairs */ for (cur = res->header; cur; cur = cur->next) { sprintf(buffer, "%s: %s\r\n", cur->key, cur->value); strcat(header, buffer); } /* set end of header */ strcat(header, "\r\n"); /* send header */ if ((status = hsocket_send(res->sock, header, strlen(header))) != H_OK) return status; res->out = http_output_stream_new(res->sock, res->header); return H_OK; }