Xcode中使用C语言发起HTTP请求

Xcode配置:

Project > Target > Build Phases > Link Binarry With Libraries > + > search libcurl.4.tbd > Add

代码:

#include 
#include 

int main(int argc, const char * argv[]) {
    CURL *curl;
    CURLcode res;
    
    curl = curl_easy_init();
    if(curl){
        curl_easy_setopt(curl, CURLOPT_URL, "https://www.baidu.com");
        res = curl_easy_perform(curl);
        
        if(CURLE_OK == res){
            char *ct;
            res = curl_easy_getinfo(curl, CURLINFO_CONTENT_TYPE, &ct);

            if((CURLE_OK ==res) && ct);
//                printf("Content-Type: %s", CURLE_OK);
        }
        curl_easy_cleanup(curl);
    }
    return 0;
}

 

赞(0)

评论 抢沙发

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址