• linux c使用socket进行http 通信,并接收任意大小的http响应(五)


     http.c data2.c http_url.c http.h data2.h http_url.h主要实现的功能是通过URL结构体来实现HTTP通信,你可以把这三个文件独立出来,作为HTTP通信模块来用
        一个简单的使用例子:

    #include <stdio.h>
    #include <stdlib.h>
    #include <string.h>
    #include "http.h"//要将上面6个文件和此文件放在同一文件夹被当中,将上面6个文件和本程序同时编译
    
    //程序功能:使用luci_username=root&luci_password=admin登录http://192.168.88.1/cgi-bin/luci
    int main()
    {
        char *httpRespond=NULL;//用于接收存储有HTTP响应的动态内存的指针,一定要初始化为NULL,要不然使用一些调试工具来检测的话,会出错
        URL httpInfo;
    
        Init_URL(&httpInfo,"http://192.168.88.1/cgi-bin/luci","luci_username=root&luci_password=admin");//初始化URL结构体,第二个参数可以为NULL
    
    
        if(1==http_perform_url(&httpInfo,&httpRespond))//进行HTTP通信操作,并将响应结果的动态内存指针保存到httpRespond
        {
            printf("
    通信成功!
    ");
        }
    
        if(NULL!=httpRespond)
            {
                printf("
    httpRespond is %s
    
    ",httpRespond);
                httpBuffer_free(httpRespond);//动态内存是可回收垃圾,为了环保,一定要记得回收!即使通信失败,依旧可能分配了动态内存用于存储失败的信息
            }
        return 0;
    }

    好吧,我现在终于学会了插入代码的功能,但是我前面写的东西我不打算改了。

  • 相关阅读:
    generator
    JS 中 apply 、call 、bind的详解
    前端面试题(24-js)
    JS原型链深入了解
    Java12新特性
    Java11-ZGC
    Java11新特性
    Java10新特性
    Java9新特性
    CF1385E【Directing Edges】 (拓扑排序)
  • 原文地址:https://www.cnblogs.com/thegodofthunder/p/7227165.html
Copyright © 2020-2023  润新知