帮助需要对libcurl的编程发送HTTP HEAD请求 [英] help needed on libcurl programming in sending HTTP HEAD Request

查看:2722
本文介绍了帮助需要对libcurl的编程发送HTTP HEAD请求的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要使用以下的libcurl澄清:

I need clarifications on using libcurl for the following:

我需要发送如下所示::一个HTTP HEAD请求

I need to send an http HEAD request shown as below ::

HEAD /mshare/3/30002:12:primary/stream_xNKNVH.mpeg HTTP/1.1
Host: 192.168.70.1:8080
Accept: */*
User-Agent: Kreatel_IP-STB
getcontentFeatures.dlna.org: 1

在code我写了(如下图所示),在发送方式略有不同HEAD请求:

The code I wrote (shown below) , sends the HEAD Request in slightly different way:

 curl_global_init(CURL_GLOBAL_ALL);
 CURL* ctx = NULL;
 const char *url = "http://192.168.70.1:8080/mshare/3/30002:12:primary/stream_xNKNVH.mpeg" ;
 char *returnString;
 struct curl_slist *headers = NULL;
 ctx = curl_easy_init();
 headers = curl_slist_append(headers,"Accept: */*");
 headers = curl_slist_append(headers,"User-Agent: Kreatel_IP-STB");\
 headers = curl_slist_append(headers,"getcontentFeatures.dlna.org: 1");
 headers = curl_slist_append(headers,"Pragma:");
 headers = curl_slist_append(headers,"Proxy-Connection:");
 curl_easy_setopt(ctx,CURLOPT_HTTPHEADER , headers );
 curl_easy_setopt(ctx,CURLOPT_NOBODY ,1 );
 curl_easy_setopt(ctx,CURLOPT_VERBOSE, 1);
 curl_easy_setopt(ctx,CURLOPT_URL,url );
 curl_easy_setopt(ctx,CURLOPT_NOPROGRESS ,1 );
 curl_easy_perform(ctx);
 curl_easy_cleanup(ctx);
 curl_global_cleanup();

上面显示的code发送的形式略有不同的HEAD请求(如下所示)

The code shown above sends the HEAD Request in slightly different form (shown below)

HEAD http://192.168.70.1:8080/mshare/3/30002:12:primary/stream_xNKNVH.mpeg HTTP/1.1
Host: 192.168.70.1:8080
Proxy-Connection: Keep-Alive
Accept: */*
User-Agent: Kreatel_IP-STB
getcontentFeatures.dlna.org: 1

任何一个可以,分享相应的code?

Can any one , share the appropriate code ?

推荐答案

如果你不想使用HTTP_PROXY envirionment,由空值象下面这样调用函数。

if you don't want to use http_proxy envirionment, call function by empty value like below.

curl_easy_setopt(curl, CURLOPT_PROXY, "");

这篇关于帮助需要对libcurl的编程发送HTTP HEAD请求的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆