int main(int argc, char *argv[]) { struct ns_mgr mgr; int i; ns_mgr_init(&mgr, NULL); /* Process command line arguments */ for (i = 1; i < argc; i++) { if (strcmp(argv[i], "--show-headers") == 0) { s_show_headers = 1; } else if (strcmp(argv[i], "--hexdump") == 0 && i + 1 < argc) { mgr.hexdump_file = argv[++i]; } else { break; } } if (i + 1 != argc) { fprintf(stderr, "Usage: %s [--show_headers] [--hexdump <file>] <URL>\n", argv[0]); exit(EXIT_FAILURE); } ns_connect_http(&mgr, ev_handler, argv[i], NULL); while (s_exit_flag == 0) { ns_mgr_poll(&mgr, 1000); } ns_mgr_free(&mgr); return 0; }
bool HttpClient::send(NanCallback* onProgress, NanCallback* onDone) { const char* url = this->_url.c_str(); const char* method = this->_method.length() > 1 ? this->_method.c_str() : "GET"; const char* headers = this->_requestHeaders.c_str(); const char* body = this->_requestData.c_str(); struct ns_connection* con = ns_connect_http(&HttpClient::sNsMgr, ev_handler, method, url, headers, body); con->user_data = this; this->_onDone = onDone; this->_onProgress = onProgress; return true; }
int sj_http_call(struct v7 *v7, const char *url, const char *body, size_t body_len, const char *method, v7_val_t cb) { struct ns_connection *nc; struct user_data *ud = NULL; nc = ns_connect_http(&sj_mgr, fossa_ev_handler, url, 0, body); if (nc == NULL) { sj_http_error_callback(v7, cb, -2); return 1; } ud = calloc(1, sizeof(*ud)); ud->v7 = v7; ud->cb = cb; nc->user_data = ud; return 0; }