<div dir="ltr">Hi,<div><br></div><div>I've a small C code and I can send and receive from google.</div><div>Here is the code</div><div><br></div><div>---------</div>char HEADERS[] = "GET /search?q=arduino HTTP/1.1\r\nHost: <a href="http://www.google.com">www.google.com</a>\r\nConnection: close\r\n\r\n";<br>char HOST_NAME_PORT[] = "<a href="http://www.google.com:443">www.google.com:443</a>";<br>const char* PREFERRED_CIPHERS = "HIGH:!aNULL:!kRSA:!SRP:!PSK:!CAMELLIA:!RC4:!MD5:!DSS";<br><br><div>void init_openssl()<br>{<br>    SSL_load_error_strings();<br>    SSL_library_init();<br>}<br><br>void CreateSSL()<br>{<br> // Create SSL context<br> meth = SSLv23_client_method();<br> if (!meth) throw Exception("SSL: method");<br><br> ctx = SSL_CTX_new(meth);<br> if (!ctx) throw Exception("SSL: SSL_CTX_new");<br><br> old_opts = SSL_CTX_set_options(ctx, SSL_OP_ALL);<br><br> web = BIO_new_ssl_connect(ctx);<br> if (!web) throw Exception("SSL: BIO_new_ssl_connect");<br>}<br><br>void ConnectSSL()<br>{<br> // Connect<br> res = BIO_set_conn_hostname(web, HOST_NAME_PORT);<br> if (!res) throw Exception("SSL: BIO_ctrl");<br><br> res = BIO_get_ssl(web, &ssl);<br> if (!res) throw Exception("SSL: BIO_ctrl");<br><br> res = SSL_set_cipher_list(ssl, PREFERRED_CIPHERS);<br> if (!res) throw Exception("SSL: SSL_set_cipher_list");<br><br> res = BIO_do_connect(web);<br> if (res <= 0) throw Exception("SSL: BIO_do_connect");<br><br> res = BIO_do_handshake(web);<br> if (res <= 0) throw Exception("SSL: BIO_do_handshake");<br>}<br><br>void SendSSL()<br>{<br> // Send<br> err = BIO_puts(web, HEADERS);<br> if (err <= 0) throw Exception("SSL: BIO_puts");<br>}<br><br>void ReceiveSSL()<br>{<br> // Read<br> sResult = "";<br> for (;;) {<br>  len = BIO_read(web, buf, sizeof(buf));<br>  sResult += buf;<br>  if (len <= 0)<br>   break;<br> }<br>}<br><br>void TestProc()<br>{<br> init_openssl();<br><br> CreateSSL();<br> ConnectSSL();<br> SendSSL();<br> ReceiveSSL();<br><br> // Next request<br> //<br><br> lTmp = new TStringList;<br> lTmp->Add(sResult);<br> lTmp->SaveToFile("c:\\temp\\a1.htm");<br><br> // Free<br> BIO_free_all(web);<br> EVP_cleanup();<br><br>}<br><br><div>---------</div><div>It is ok for one request.</div><div><br></div><div>My problem when I trying to send a new search request to google it works only when I call </div><div> CreateSSL();<br> ConnectSSL();<br></div><div>again</div><div><br></div><div>so my new search request is </div><div> CreateSSL();<br> ConnectSSL();<br> SendSSL();<br> ReceiveSSL();<br><br></div><div>Is this normal?</div><div><br></div><div>When I trying to use</div><div> SendSSL();<br> ReceiveSSL();</div><div>only</div><div>I have got a page with errors (I think). The response is shorter, starts with 0 (not with HTTP/1.1 200 OK)</div><div><br></div><div>What may the problem?</div><div><br></div><div><br><div><div dir="ltr" class="gmail_signature" data-smartmail="gmail_signature">Thanks for your help</div></div></div></div><div dir="ltr" class="gmail_signature" data-smartmail="gmail_signature"><br></div><div dir="ltr" class="gmail_signature" data-smartmail="gmail_signature"><br></div></div>