简体   繁体   English

使用cur中的cur发送HTTP Get请求

[英]send HTTP Get request using Curl in c

Please help me to implement an HTTP Get request using curl in C. 请帮我在C中使用curl实现HTTP Get请求。

I need to hit URL with parameters like https://www.googleapis.com/tasks/v1/users?name=pradeep&lastname=singla I used CURLOPT_HTTPHEADER to set parameters with Header but without success. 我需要使用https://www.googleapis.com/tasks/v1/users?name=pradeep&lastname=singla等参数来点击URL我使用CURLOPT_HTTPHEADER来设置Header参数但没有成功。 I implemented it like 我实现了它

struct curl_slist* contentheader = NULL;    

contentheader = curl_slist_append(contentheader, "name=pradeep");
contentheader = curl_slist_append(contentheader, "lastname=singla");

curl_easy_setopt(curl, CURLOPT_URL, "https://www.googleapis.com/tasks/v1/users");
curl_easy_setopt(curl, CURLOPT_HTTPHEADER, contentheader);
curl_easy_perform(curl); 

In this case an error occured like "no correct APi request". 在这种情况下,出现错误,如“没有正确的APi请求”。 So I thought that I can use 所以我认为我可以使用

char *charff = "name=pradeep&lastname=singla";    
curl_easy_setopt(curl, CURLOPT_POSTFIELDS, charfff);
curl_easy_setopt(curl, CURLOPT_HTTPGET, 1L); curl_easy_perform(curl);

but the same error is occurring. 但是同样的错误正在发生。

Can anyone please help me ? 谁能帮帮我吗 ? I can put my request for both POST and GET method because server method may change anytime. 我可以提出POST和GET方法的请求,因为服务器方法可能随时更改。

The URL is just a URL even with "parameters" and you set it in full with CURLOPT_URL . 即使使用“参数”,URL也只是一个URL,您可以使用CURLOPT_URL完整地设置它。

They're not headers and they're not postfields. 他们不是标题,他们不是后场。

CURL *curl = curl_easy_init();
curl_easy_setopt(curl, CURLOPT_URL, 
    "https://www.googleapis.com/tasks/v1/users?name=pradeep&lastname=singla");
curl_easy_perform(curl);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM