cURL / Mailing Lists / curl-library / Single Mail

curl-library

Is it possible to simply write to a socket?

From: Igor Korot <ikorot01_at_gmail.com>
Date: Thu, 12 Jul 2012 16:49:42 -0700

Hi, ALL,
I'm transferring the code from VB to C/C++ to make it cross-platform.
In VB, there is following code:

[code]
Dim boundary As String = "---------------------------" &
DateTime.Now.Ticks.ToString("x")
Dim newLine As String = System.Environment.NewLine
Dim boundaryBytes As Byte() =
System.Text.Encoding.ASCII.GetBytes(newLine & "--" & boundary &
newLine)
Dim request As Net.HttpWebRequest = Net.WebRequest.Create(uri)

request.ContentType = "multipart/form-data; boundary=" & boundary
request.Method = "POST"
request.KeepAlive = True
request.Credentials = Net.CredentialCache.DefaultCredentials

Using requestStream As IO.Stream = request.GetRequestStream()
            requestStream.Write(boundaryBytes, 0, boundaryBytes.Length)
End Using
[/code]

AFAIU, it just simply writes boundary bytes to the socket as an ASCII
bytes sequence.
There is post-ing involved, no form submittal
Is it possible to do the same with libcurl?

Because with the following approach:

[code]
curl_easy_setopt( handle, CURLOPT_POSTFIELDS, const_cast<char *>(
boundary.ToAscii().data() ) );
curl_easy_setopt( handle, CURLOPT_POSTFIELDSIZE, sizeof(
const_cast<char *>( boundary.ToAscii().data() ) ) );
curl_easy_perform( handle );
[/code]

I am getting this:

[quote]
Content-Type: application/x-www-form-urlencoded

* upload completely sent off: 4 out of 4 bytes
< HTTP/1.1 500 Internal Server Error
< Cache-Control: private
< Content-Length: 4784
< Content-Type: text/html; charset=utf-8
[/quote]

which means I am just simply posting data to the form, which is incorrect.

Am I suppose to use CURLOPT_READFUNCTION/CULOPT_READDATA for that?

Thank you.
-------------------------------------------------------------------
List admin: http://cool.haxx.se/list/listinfo/curl-library
Etiquette: http://curl.haxx.se/mail/etiquette.html
Received on 2012-07-13