使用LibCurl发送http post请求 [英] Sending http post request with LibCurl

查看:370
本文介绍了使用LibCurl发送http post请求的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,



我想创建一个帖子请求并使用libCURL将其发送到服务器任何人都可以帮助我。

如果这是我的样品请求



< GetCapabilities version =" 1.0.0" service =" WCS">

< section> / WCS_Capabilities / Capability< / section>

< / GetCapabilities>



我怎么想在curl选项中设置xml元素及其属性值。



请帮助,这非常重要。

Hi all,

I want to create a post request and send it to server using libCURL can anyone help me in that.
If this is my sample request

<GetCapabilities version="1.0.0" service="WCS">
<section>/WCS_Capabilities/Capability</section>
</GetCapabilities>

how am I suppose to set the xml elements and their attributes value in the curl options.

Please help, this is really important.

推荐答案

最简单的方法是三次调用 curl_easy_setopt



CURLOPT_POST 告诉图书馆你要发帖子。



CURLOPT_POSTFIELDS 告诉库这是一个指向您希望以服务器期望的形式发送的数据的指针。您可以确保此格式正确无误。如果您正在使用XML期望的Web服务,那么您将构建XML,libCurl将无济于事。



CURLOPT_POSTFIELDSIZE 告诉图书馆你要发送的数据的大小。



或者你可以阅读 curl_easy_setopt [ ^ ] docs并了解如何使用回调来形成数据 - 但是否需要它取决于您与服务器的交互方式。
The simplest way is three calls to curl_easy_setopt

CURLOPT_POST tells the library that you're going to do a post.

CURLOPT_POSTFIELDS tells the library that this is a pointer to the data that you want to send in exactly the form the server expects it. It's up to you to make sure that this format is correct. If you're using an XML expecting webservice you get to form the XML, libCurl won't help.

CURLOPT_POSTFIELDSIZE tells the library the size of the data you want sent.

Alternatively you can read the curl_easy_setopt[^] docs and see how you can use a callback to form the data - but whether you need that depends on how you interact with the server.


这篇关于使用LibCurl发送http post请求的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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