"Content-Length" calculation

How do I calculate "Content-Length" value, using Inet in VB6

Page 1 of 1

3 Replies - 4695 Views - Last Post: 18 February 2010 - 07:13 PM Rate Topic: -----

#1 rtoogood@choiceware.ca  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 08-February 10

"Content-Length" calculation

Posted 16 February 2010 - 09:29 AM

Hello,

I am trying to post a file to a web server using Inet in VB6. The file needs to be sent with a "Content-Length" header. I need help in calculating the value of the "Content-Header".

What makes up the "Content-Length" value? Is it simply the length of the file being sent in bytes, or does it include the length of any header files as well? I've also seen reference to "Octets" in my research. Does the "Content-Length" need to be reported in "Octets" or in "Bytes" (I thought Octets and Bytes were one in the same)? If it needs to be in "Octets", how do I convert from "Bytes"?

Is This A Good Question/Topic? 0
  • +

Replies To: "Content-Length" calculation

#2 JackOfAllTrades  Icon User is online

  • Saucy!
  • member icon

Reputation: 5959
  • View blog
  • Posts: 23,229
  • Joined: 23-August 08

Re: "Content-Length" calculation

Posted 16 February 2010 - 03:11 PM

Octets and bytes are the same (i.e., a byte is an octet of bits).

Content length is exclusive of headers, and most of the time you can pass -1 as the content length and the server will keep accepting data until you stop sending it.
Was This Post Helpful? 0
  • +
  • -

#3 rtoogood@choiceware.ca  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 08-February 10

Re: "Content-Length" calculation

Posted 18 February 2010 - 05:04 PM

View PostJackOfAllTrades, on 16 February 2010 - 02:11 PM, said:

Octets and bytes are the same (i.e., a byte is an octet of bits).

Content length is exclusive of headers, and most of the time you can pass -1 as the content length and the server will keep accepting data until you stop sending it.



Thanks for your quick response. I've tried sending the file with the content length set to -1, as well as the actual number of bytes. In every case, I'm able to establish a connection and the file appears to be transmitted (I.e. there is a 10 second pause), but no file is received at the server. Would you mind having a look at my code to see if you can tell me what I'm doing wrong?

Thanks...

Public Sub TransmitFileTest()

Dim Filename As String
Dim Headers As String
Dim Url As String

'Filename to transfer
Filename = "C:\myDir\myFile.xml"

'Set Properties
Url = "https://serverUrl.com/sft"
Inet1.Protocol = icHTTPS
Inet1.AccessType = icUseDefault
Inet1.Url = Url
Inet1.RemotePort = 443
Inet1.RemoteHost = "https://sserverUrl.com/sft"

'Create Header (Authorization is base64 encoded - i.e. "Authorization: Basic UserCode:Password")
Headers = "Authorization: Basic " & "YhvaS10MsV9zdWJhcnVjYW5faHadsfasdfcHNa1clQ3RpbmdAY2NvdWasfMTd=" & vbCrLf & "Content-Length: " & Trim(Str$(FileLen(Filename))) & vbCrLf
    
'Transmit file
Inet1.Execute Url, "POST", Filename, Headers

While Inet1.StillExecuting
    DoEvents
Wend

StillExecuting:
If Inet1.StillExecuting = -1 Then GoTo StillExecuting

End Sub


Was This Post Helpful? 0
  • +
  • -

#4 JackOfAllTrades  Icon User is online

  • Saucy!
  • member icon

Reputation: 5959
  • View blog
  • Posts: 23,229
  • Joined: 23-August 08

Re: "Content-Length" calculation

Posted 18 February 2010 - 07:13 PM

I'm not much of a VB network guy (I have no idea what Inet1 is referring to, for example...I guess it's the Internet Transfer Control), so I'll have to let someone more knowledgeable comment on the code, but from the point of view of the HTTP transaction and what the server is expecting, you may need to pass a Content-Type header as well (text/xml, perhaps?). If you have access to the server side of the transaction it may be easier on you to debug.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1