login about faq

Hi there, I want to upload a file to a WebDav server using the C++ libraries. Below is the code I'm using: CkHttpRequest req; req.put_HttpVerb("PUT"); req.put_ContentType("multipart/form-data"); CStringA strPath; strPath.Format("/%s", uploadName); req.put_Path(strPath); req.AddFileForUpload(NULL, strFile); const char *pHead = req.generateRequestText();

which gives in pHead:

PUT /public/report.txt HTTP/1.1 Host: HOSTNAME Content-Type: multipart/form-data; boundary=------------020808030003050400040405 Content-Length: 4319

--------------020808030003050400040405 Content-Disposition: form-data; name=""; filename="report.txt" Content-Type: text/plain ...

However the WebDav server does not understand "multipart/form-data" and stores

--------------080806070104020804050800 Content-Disposition: form-data; name=""; filename="report.txt" Content-Type: text/plain

at the begin of the files and the boundary markers too... The header is fine, just sending the file data without the boundary stuff would do. Is there any other way to accomplish the task using CkHttp and CkHttpRequest?

Thanks, Dave

asked Mar 25 '13 at 08:35

Davids's gravatar image

Davids
1222


You should become familiar with what the actual HTTP request it is that you're trying to send would look like. For example, if you wanted this:

PUT /pub2/folder1/folder2/item1.txt HTTP/1.1
Content-Type: text/plain
Content-Length: 4

abcd

Then you would call the http.PutText method.

link

answered Mar 25 '13 at 18:03

chilkat's gravatar image

chilkat ♦♦
11.8k316358420

Well, eeemh. 
Yes, I know there are several methods to upload but I want to upload a LARGE file which 
I cannot load in a buffer first.
Lets say:
PUT /pub2/folder1/folder2/item1.txt HTTP/1.1
Content-Type: text/plain
Content-Length: 9891789794

... the data ...
How would I do that with chilkat?
link

answered Mar 26 '13 at 05:20

Davids's gravatar image

Davids
1222

Build your HTTP request using the CkHttpRequest object.

With the CkHttpRequest object...
Set the ContentType property = "text/plain".
Set the HttpVerb property = "PUT".
Set the Path property to whatever it should be.
Set the body by calling StreamBodyFromFile (see the reference documentation)

Send the request via the http.SynchronousRequest method.

link

answered Mar 26 '13 at 13:52

chilkat's gravatar image

chilkat ♦♦
11.8k316358420

Hi, in fact I wasn't aware of StreamBodyFromFile. While the proposed solution looks good, 
I don't get it working. What I did:

CkHttpRequest req;
req.put_ContentType("text/plain");
req.put_HttpVerb("PUT");
req.put_Path(strPath);
bool br = req.StreamBodyFromFile(strFile);
CkHttpResponse *resp =  m_http.SynchronousRequest(m_strHost, 80, false, req);

Using PUT as verb there is no Content-Length at all in the header.
Using POST as verb the Content-Length is there, but is always 0.
The Header is sent in both cases and the file contents is streamed too, but without a valid 
Content-Length the server is not happy. BTW, I can't set Content-Length for myself.

Any ideas?

Regards, Dave
link

answered Mar 27 '13 at 05:47

Davids's gravatar image

Davids
1222

Can you set the Content-Length yourself using the AddHeader method? Also, your ContentType is "text/plain" - is the large file that you are sending really a text file? If it has binary data, you might want to use application/octet-stream instead.

(Mar 27 '13 at 11:10) jpbro ♦

In my test program the fils IS actually a text file, but it doesn't make any difference which Content-Type is set. Calling AddHeader does not work either.

(Mar 27 '13 at 11:26) Davids
Your answer
toggle preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or __italic__
  • **bold** or __bold__
  • link:[text](http://url.com/ "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported

Tags:

×50
×2

Asked: Mar 25 '13 at 08:35

Seen: 1,503 times

Last updated: Mar 27 '13 at 11:26

powered by OSQA