cURL / Mailing Lists / curl-library / Single Mail

curl-library

Re: HELP: how can i do POST with setting URL to " / "

From: Michael Wood <esiotrot_at_gmail.com>
Date: Thu, 29 Jul 2010 17:31:03 +0200

Hi

2010/7/29 <xiusandake_at_yahoo.co.jp>:
>
> i need to create a http client for sending a http request to a http server
> as following format:
>
> POST / HTTP/1.1
> HOST: 192.168.1.2
> Accept: ... ...
> Content-type: ... ...
> ... ...
>
> so i write a source code like this:
>
> easy_set_opt(curl, URL, " / ");
> curl_slist_append(slist, "HOST: 192.168.1.2");
> ... ...
> curl_easy_setopt(curl, CURLOPT_HTTPHEADER, slist);
> curl_easy_perform(curl);

No, just do this:

curl_easy_setopt(curl, CURLOPT_URL, "http://192.168.1.2/");
curl_easy_perform(curl);

Don't set the Host header manually. libcurl will convert that into:

POST / HTTP/1.1
Host: 192.168.1.2
...

-- 
Michael Wood <esiotrot_at_gmail.com>
-------------------------------------------------------------------
List admin: http://cool.haxx.se/list/listinfo/curl-library
Etiquette:  http://curl.haxx.se/mail/etiquette.html
Received on 2010-07-29