<div dir="ltr">Hi,<div><br></div><div>I'm trying to connect to <a href="http://www.google.com">www.google.com</a> on 443 port with SSL but my code shows an error at ssl_write.</div><div>This code is written in C++ Builder on Windows.</div><div>Everything is good before this point</div><div> err = SSL_write(ssl, buf, strlen(buf));<br></div><div><br></div><div>But after that err=-1 and code=1 (means SSL_ERROR_SSL )</div><div><br></div><div>What may the problem?</div><div><br></div><div>My question also: I have found that maybe I have to use ERR_get_error but this function is in an another dll (libeay32) how will this function connect to the ssl instance?</div><div><br></div><div>Thanks for your help</div><div><br></div><div><br></div>void init_openssl()<br>{<br>    SSL_load_error_strings();<br>    SSL_library_init();<br>}<br><br>AnsiString s, HEADERS = "GET /search?q=test HTTP/1.1\r\nHost: <a href="http://www.google.com">www.google.com</a>\r\nUser-Agent: OpenSSL\r\n\r\n";<br><div><br></div><div>void TestProc()<br>{<br> WORD wVersionRequested;<br> WSADATA wsaData;<br> struct sockaddr_in sa;<br> PSSL_METHOD meth;<br> u_long iMode = 1;<br> char buf[1024];<br><br> strcpy(buf, HEADERS.c_str());<br><br> wVersionRequested = MAKEWORD(2, 2);<br> err = WSAStartup(wVersionRequested, &wsaData);<br> if (err != 0) throw Exception("WSAStartup");<br><br> init_openssl();<br><br> // Create socket<br> sd = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP  );<br> memset(&sa, 0, sizeof(sa));<br> sa.sin_family      = AF_INET;<br> sa.sin_addr.s_addr = inet_addr("216.58.213.4");   /* Server IP : this <a href="http://google.com">google.com</a> */<br> sa.sin_port        = htons(443);                  /* Server Port number */<br> err = connect(sd, (struct sockaddr*) &sa, sizeof(sa));<br> if (err == -1) throw Exception("SOCKET: connect");<br> err = ioctlsocket(sd, FIONBIO, &iMode);<br> if (err == -1) throw Exception("SOCKET: set blocking mode");<br><br> // Create SSL context<br> meth = SSLv23_server_method();<br> if (!meth) throw Exception("SSL: method");<br> ctx = SSL_CTX_new(meth);<br> if (!meth) throw Exception("SSL: context");<br> ssl = SSL_new(ctx);<br> if (!ssl) throw Exception("SSL: ssl");<br> SSL_set_fd(ssl, sd);<br><br> // Connect<br> err = SSL_connect(ssl);<br> if (err == -1) throw Exception("SSL: SSL_connect");<br><br> // Send<br> s = HEADERS;<br> err = SSL_write(ssl, buf, strlen(buf)); 

 /* error at this point, code = SSL_ERROR_SSL */<br> code = SSL_get_error(ssl, err);<br> if (err == -1) throw Exception("SSL: send: "+s);<br>}<br></div><div><br></div><div><br clear="all"><div><div dir="ltr" class="gmail_signature" data-smartmail="gmail_signature"><br></div></div></div></div>