Hi, friends
I'm developing a module to connect C programs with WebServices and newly I've used OpenSSL. Actually it hasn't very difficult, although I had some problem. It's very important to set properly the method to use. I'm connecting with a JBoss HTTPs WebService and I had to set this one:
meth = TLSv1_client_method();
ctx = SSL_CTX_new (meth);
I copy bellow the main function I had used, to send the HTTP POST message, I hope it'll be usefull for you:
int sendPOST(void* sd, SSL* ssl, ;char* server, char* port, char* post, char* action, char* csoap, char *response){
int ret=0;
char msg[5000]="";
char buff[5000]="";
int err=0;
int len=0;
char header[200]="";
// Setting HTTP Headers
sprintf(msg,"POST %s HTTP/1.1\r\n", post);
sprintf(header,"Host: %s:%s\r\n", server, port);
len=strlen(msg) ;
memcpy(msg + len , header, strlen(header));
len+=strlen(header);
strcpy(header,"Content-Type: application/x-www-form-urlencoded; charset=utf-8\r\n");
memcpy(msg + len, header, strlen(header));
len+=strlen(header);
sprintf(header,"Content-Length: %d\r\n", strlen(datos));
memcpy(msg + len, header, strlen(header));
len+=strlen(header);
sprintf(header,"SOAPAction: %s\r\n\r\n",action);
memcpy(msg + len, header, strlen(header));
len+=strlen(header);
// Adding csoap
memcpy(msg + len, datos, strlen(datos));
if(sd!=NULL){
// No SSL Connections
err=send((int)sd, msg, len + strlen(datos),0);
if (err == SOCKET_ERROR) {
printf("send() failed with error: %d\n", WSAGetLastError());
closesocket((int)sd);
WSACleanup();
exit(1);
}
do {
err = recv((int)sd, buff, sizeof(buff) - 1, 0);
if ( err > 0 )
printf("Bytes received: %d\n", err);
else if ( err == 0 )
printf("Connection closed\n");
else
printf("recv failed with error: %d\n", WSAGetLastError());
} while( err > 0 );
}else{
// SSL Connections
err = SSL_write (ssl, msg, len + strlen(datos)); CHK_SSL(err);
err = SSL_read (ssl, buff, sizeof(buff) - 1);
CHK_SSL(err);
buff[err] = '\0';
SSL_shutdown (ssl);
}
strcpy(respuesta, buff);
return ret;
}
Showing posts with label POST. Show all posts
Showing posts with label POST. Show all posts
Wednesday, March 5, 2008
Thursday, January 24, 2008
CSoap and Visual Studio
First of all, I’m sorry for my English, but I want to improve it and this is a good way.
Well, this is my first solution.
Many times I have had to connect a c program to a Web Service, in Windows with MFC is too easy. I have a dll, which connects the c program with whatever Web Service only updating some xml files.
But, when you need to connect a c program running in other OS, you'll need to try other solutions.
The best, for me, it's CSoap.
However when I had to develop that connection I only had Windows Systems and well, I tried to connect CSoap in a Visual Studio Project.
It wasn't easy for me to find examples about CSOAP for Visual C++, and that is why I put that solution here.
Here is the original link to my source files https://sourceforge.net/tracker/download.php?group_id=74977&atid=542567&file_id=250457&aid=1816455
Well, this is my first solution.
Many times I have had to connect a c program to a Web Service, in Windows with MFC is too easy. I have a dll, which connects the c program with whatever Web Service only updating some xml files.
But, when you need to connect a c program running in other OS, you'll need to try other solutions.
The best, for me, it's CSoap.
However when I had to develop that connection I only had Windows Systems and well, I tried to connect CSoap in a Visual Studio Project.
It wasn't easy for me to find examples about CSOAP for Visual C++, and that is why I put that solution here.
Here is the original link to my source files https://sourceforge.net/tracker/download.php?group_id=74977&atid=542567&file_id=250457&aid=1816455
Subscribe to:
Posts (Atom)