资源简介
访问Https通信协议做的网站的时候,建立的socket套接字需要SSL协议认证 ,加密之后,才可以和网站建立资源
代码片段和文件信息
/*
* OpenSSL SSL/TLS Https Client example
* Only for Unix/Linux:
* cc -c https.c
* cc -o https https.c -lssl
* OpenSSL library needed.
*
* 同时支持普通的socket连接以及基于普通socket基础之上的ssl
* 连接。这对于已有的socket程序修改来说会比较方便,不至于
* 和原来的结构发生太大的冲突.
* 要注意的一点,似乎当使用socket套接字来创建ssl连接的时候
* 如果套接字是采用非阻塞方式建立的话,会导致ssl会话失败,不
* 知道为什么。所以这里对于提供给https的套接字采用了普通的
* connect方法创建。
*
*/
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#define BUF_LEN 1024
#define MAX_STRING_LEN 2048
//xnet_select x defines
#define READ_STATUS 0
#define WRITE_STATUS 1
#define EXCPT_STATUS 2
/* flag to set request with ssl or not. */
static int bIsHttps = 1;
static int timeout_sec = 10;
static int timeout_microsec = 0;
void err_doit(int errnoflag const char *fmt va_list ap);
void err_quit(const char *fmt ...);
int create_tcpsocket(const char *host const unsigned short port);
int xnet_select(int s int sec int usec short x);
int main(int argc char* argv[])
{
char* host = “127.0.0.1“;
unsigned short port = 80;
int fd;
SSL *ssl;
SSL_CTX *ctx;
int nret;
char buf[BUF_LEN];
char* requestpath = “/“;
if( argc == 5 )
{
host = argv[1];
port = atoi(argv[2]);
requestpath = argv[3];
bIsHttps = atoi(argv[4]);
}
else
printf(“Argc Err !!!“);
printf(“host:%s port:%d requestpath:%s\n“hostportrequestpath);
/* make connection to the cache server */
fd = create_tcpsocket(host port);
printf(“建立套接字\n“);
/* http request. */
sprintf(buf “GET %s HTTP/1.0\r\nHost: %s\r\n\r\n“requestpath host);
if(bIsHttps != 1)
{
if(xnet_select(fd timeout_sec timeout_microsec WRITE_STATUS)>0)
{
/* send off the message */
printf(“发送数据内容:%s\n“buf);
write(fd buf strlen(buf));
}
else
{
err_quit(“Socket I/O Write Timeout %s:%d\n“ host port);
}
printf(“Server response:\n“);
while (xnet_select(fd timeout_sec timeout_microsec READ_STATUS)>0)
{
if ((n = read(fd buf BUF_LEN-1)) > 0)
{
buf[n] = ‘\0‘;
printf(“%s“ buf);
}
else
{
break;
}
}
// close the plain s
相关资源
- 信息素S型更新的耦合ACO算法及其应用
- RT_7_lite_精简列表.docx
- 可以在XE下使用的DosCommand,捕获控制
- excelApi 和安装工具
- GBT 20438.5-2017(IEC 61508-5-2010) 电气 电
- cmd.exe
- 解决检索 COM 类工厂中 CLSID 为 {96749
- Adobe cc 2018 全套破解版 ps pr等
- Bc衰变中的D波衰减器ηc211D2,ψ
- IDEFixPack2007Reg43
- ArcGIS Server 10.4.x 系列 授权文件
- UsbTrace v2.8.0.80 64位和32位破解版
- 跟踪,检测IRP的优秀工具IRPTrace
- DebugView、DriverMonitor、IRPTrace、WinObj、
- IRPTrace 破解版
- 如何使用VC和OD调试OCX控件
- PcShutDownByTime.zip
- Cisco无线AP全部配置文件(AIR-1200系列
- 安卓手机PC端一键重启工具
- ManualIciMapping_v3.1
- FreeRTOS采样ADC+KEY事件信号+DMA串口收发
- Microservices_Designing_Deploying
-
Design for em
bedded Image Processing on FPG - A Sequential Bundle Method for Solving a MPEC
- Concurrency in Go(EarlyRelease) 无水印p
- Concurrency in Go Tools and Techniques for Dev
- BTCETH开发
- cfx中ccl语言使用手册
- STC15F
- 解读AT89C2051遥控接收器电路设计原理
评论
共有 条评论