• 大小: 563KB
    文件类型: .rar
    金币: 1
    下载: 0 次
    发布日期: 2021-05-15
  • 语言: C/C++
  • 标签: C语言  https  http  openssl  

资源简介

纯C语言实现https的post和get,不依赖任何库。支持window,linux等多平台,因此get及post效率较高,可移植性很好。本次上传的是vc6下的完整工程的压缩包,解压后可直接使用。若要在linux下编译和运行,可按照压缩包内Linux下编译运行https的帮助文档来操作。

资源截图

代码片段和文件信息

#include “http.h“
#include “http_parser.h“

#include 
#include 
#include 

#ifdef WIN32
#include 
#ifdef WINCE
#pragma comment( lib “ws2.lib“) 
#else
#pragma comment( lib “ws2_32.lib“) 
#endif
#else
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include  
#include 
#include 
#include 

#define _strdup strdup
#define _stricmp strcasecmp
#define _strnicmp strncasecmp

#endif


#if FT_SUPPORT_HTTPS

#ifdef USEOPENSSL

#include 
#include 

#else 
#include “krypton.h“
#endif


#endif

const int kSelectRead = 1 << 0;
const int kSelectWrite = 1 << 1;
const int kSelectError = 1 << 2;

#define DEFAULT_USER_AGENT_STR “User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:29.0) Gecko/20100101 Firefox/29.0\r\n“
#define CONNECT_STR “Connection: close\r\n“
#define ACCEPT_STR “Accept: */*\r\n“
#define CONTENT_LENGTH_STR “Content-Length“
#define CONTENT_TYPE_STR “Content-Type:application/x-www-form-urlencoded\r\n“
#define CONTENT_DISPOSITION_STR “Content-Disposition“
#define CRLF “\r\n“

enum parser_statue_e { PARSERD_NONE = 0 PARSERD_FIELD PARSERD_VALUE PARSERD_BODY };

enum proto_type_e { PROTO_HTTP = 0 PROTO_HTTPS };

#ifdef WIN32
typedef SOCKET socket_t;
#define HTTP_INVALID_SOCKET INVALID_SOCKET
#define HTTP_EINTR WSAEINTR
#define HTTP_EINPROGRESS WSAEINPROGRESS
#define HTTP_EWOULDBLOCK WSAEWOULDBLOCK
#define HTTP_EALREADY WSAEALREADY
#else
typedef int socket_t;
#define HTTP_INVALID_SOCKET -1
#define HTTP_EINTR EINTR
#define HTTP_EINPROGRESS EINPROGRESS
#define HTTP_EWOULDBLOCK EWOULDBLOCK
#define HTTP_EALREADY EALREADY
#endif

#define RECV_BUF_SIZE 4 * 1024

struct ft_http_client_t
{
FILE* pf;
char* filename;
char* body;
char* redirect_url;
char* header_field;
char* header_value;

char* user;
data_recv_cb_t recv_cb;

unsigned long body_len;
unsigned long content_length;

enum http_request_method_e method;
enum proto_type_e proto_type;

unsigned short field_size;
unsigned short value_size;
unsigned short cur_field_size;
unsigned short cur_value_size;

#if FT_SUPPORT_HTTPS
SSL_CTX *ctx;
SSL *ssl;
#endif

socket_t fd; 
int timeout;

short status_code;
char parser_statue;
char error_code;
unsigned cancel   : 1;
unsigned exit   : 1;
unsigned download : 1;
unsigned redirect : 1;
};

#ifdef WIN32
#define socket_close closesocket
#else
#define socket_close close
#endif

#define free_member(member) if((member)) { free(member); (member) = NULL; }
#define close_socket(fd) if(fd != HTTP_INVALID_SOCKET) { socket_close(fd); fd = HTTP_INVALID_SOCKET; }
#define close_file(pf) if

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----

     文件      45287  2018-08-02 08:43  https\Debug\http.obj

     文件      77902  2018-08-02 08:43  https\Debug\http_parser.obj

     文件     225729  2018-08-02 08:43  https\Debug\krypton.obj

     文件     352324  2018-08-02 09:09  https\Debug\main.exe

     文件     304744  2018-08-02 09:09  https\Debug\main.ilk

     文件       4693  2018-08-02 09:09  https\Debug\main.obj

    I.A....    185200  2018-08-02 09:09  https\Debug\main.pch

     文件     828416  2018-08-02 09:09  https\Debug\main.pdb

     文件      50176  2018-08-02 09:09  https\Debug\vc60.idb

     文件      86016  2018-08-02 09:09  https\Debug\vc60.pdb

    I.A....     22529  2018-07-26 09:03  https\http.c

    I.A....      2221  2018-07-25 20:05  https\http.h

     文件      74049  2018-08-01 16:02  https\http_parser.c

     文件      13513  2018-08-01 16:01  https\http_parser.h

     文件      22141  2018-08-02 09:09  https\img.jpg

     文件     241070  2018-08-01 16:01  https\krypton.c

     文件       2908  2018-08-01 16:02  https\krypton.h

     文件        376  2018-08-02 09:17  https\Linux下编译运行https帮助文档.txt

     文件        944  2018-08-02 09:09  https\main.c

     文件       3749  2018-08-01 16:14  https\main.dsp

     文件        514  2018-08-01 16:14  https\main.dsw

     文件     115712  2018-08-02 09:09  https\main.ncb

     文件      49664  2018-08-02 09:09  https\main.opt

     文件       1196  2018-08-02 09:09  https\main.plg

     目录          0  2018-08-02 09:09  https\Debug

     目录          0  2019-12-24 14:15  https

----------- ---------  ---------- -----  ----

              2711073                    26


评论

共有 条评论