Problems with POST
Rosa Sanchez Guerrero
rosa.rsg at gmail.com
Mon Jul 13 12:51:24 EDT 2009
Hi, could you give me some examples about how to obtain the response of a
POST?
My code is as follows:
static void collector(void *ud, const char *data, size_t len)
{
ne_buffer *buf = ud;
ne_buffer_append(buf, data, len);
}
char* soap_call(char *url, char *message,char *content_type,char *cert)
{
char *tmp;
int i,j,length;
char *start_with = "http://";
int pos,failures;
url_parsed *url_pars;
url_parsed *url_pars_aux;
ne_session *sesion;
ne_request *request;
ne_status *status;
ne_block_reader *reader;
ne_accept_response *response;
void *data;
ne_ssl_certificate *certificate;
ne_ssl_verify_fn *verify_fn;
ne_buffer *buf = ne_buffer_create();
printf("Parametros de entrada en soap_call\n");
printf("url ===> %s\n", url);
//printf("message_body ====> %s\n", message);
if (strncasecmp(url,start_with,7)== 0)
{
//Establecemos una conexion HTTP
//Nos quedamos con el host y el path
//Establecemos una conexion HTTP con el servidor. Creamos una sesion y
enviamos una peticion
ne_sock_init();
url_pars = (url_parsed *)calloc(1, sizeof(url_parsed));
if (url_pars_aux == NULL)
{
free(url_pars);
return NULL;
}
// printf("Host ===>%s\n", url_pars_aux->host);
// printf("Path ===>%s\n", url_pars_aux->path);
// printf("Port ===>%s\n", url_pars_aux->port);
url_parsed *url_pars_aux = url_parse(url,url_pars);
sesion = ne_session_create("http",url_pars_aux->host +
2,url_pars_aux->port);
}// Fin del if de la conexion HTTP
else
{
//Establecemos una conexion HTTPS
//Nos quedamos con el host y el path
url_pars = (url_parsed *)calloc(1, sizeof(url_parsed));
url_pars_aux = url_parse(url,url_pars);
if (url_pars_aux == NULL)
{
free(url_pars);
return NULL;
}
// printf("Host ===>%s\n", url_pars_aux->host);
// printf("Path ===>%s\n", url_pars_aux->path);
// printf("Port ===>%s\n", url_pars_aux->port);
//
//Establecemos una conexion HTTP con el servidor. Creamos una sesion y
enviamos una peticion. Antes tenemos que inicializar el socket
ne_sock_init();
sesion = ne_session_create("https",url_pars_aux->host +
2,url_pars_aux->port);
certificate = ne_ssl_cert_read(cert);
verify_fn = verify(url_pars_aux->host + 2,failures,certificate);
ne_ssl_set_verify(sesion,verify_fn, url_pars_aux->host + 2);
}
//Creamos una peticion HTTP POST
url_pars_aux = url_parse(url,url_pars);
request = ne_request_create(sesion,"POST",url_pars_aux->path);
if(request == NULL)
{
return NULL;
}
ne_set_request_body_buffer(request,message,strlen(message));
ne_add_response_body_reader(request, ne_accept_2xx, collector, buf);
int ret_res2= ne_request_dispatch(request);
printf("Parametros de buffer --------------------------\n");
printf("buffer->data --------------------------> %s\n",buf->data);
printf("buffer->used --------------------------> %d\n",buf->used);
printf("buffer->length --------------------------> %d\n",buf->length);
//Liberamos las estructuras que representan los obejetos peticion,
sesion de la coexion
//y el socket
if (ne_get_status(request)->code ==200)
data = strdup(buf->data);
else{
printf("Request failed\n");
return NULL;
}
ne_buffer_destroy(buf);
ne_request_destroy(request);
ne_session_destroy(sesion);
//ne_sock_exit();
free(url_pars);
return data;
}
But when I compare the size of the message read to the size of the original
message sent to another server, the size is not the same, ie, do not get to
read the message. The size of the reply message is 4096 bytes and read 3963.
If you call the function ne_request_dispatch error occurs in the function
ne_discard. What might be the problem?
Thanks.
Rosa
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.manyfish.co.uk/pipermail/neon/attachments/20090713/57786fe9/attachment-0006.html
More information about the neon
mailing list