PowerBuilder
PowerBuilder
Add a Content-Length Header to MIME
See more MIME Examples
Demonstrates the Chilkat Mime.AddContentLength method, which computes the byte length of the entity's serialized body and adds or updates its Content-Length header. It takes no arguments and is a void method. The count is based on the transfer-encoded serialized body.
Note: The file path is relative to the application's current working directory. Absolute paths may also be used. Supply the path to your own file.
Background: Some protocols and consumers want a
Content-Length declaring the body size up front. This computes it correctly from the encoded body — the bytes actually written — rather than the decoded content, and updates any existing header so it stays accurate. Call it after the body is final; if you change the body afterward, call it again, or remove the header, since a stale length is worse than none.Chilkat PowerBuilder Downloads
integer li_rc
long li_Success
oleobject loo_Mime
string ls_ContentLength
li_Success = 0
loo_Mime = create oleobject
li_rc = loo_Mime.ConnectToNewObject("Chilkat.Mime")
if li_rc < 0 then
destroy loo_Mime
MessageBox("Error","Connecting to COM object failed")
return
end if
li_Success = loo_Mime.LoadMimeFile("qa_data/message.eml")
if li_Success = 0 then
Write-Debug loo_Mime.LastErrorText
destroy loo_Mime
return
end if
// Compute the byte length of the entity's serialized body and add (or update) its Content-Length
// header. The count is based on the transfer-encoded serialized body. It is a void method.
loo_Mime.AddContentLength()
ls_ContentLength = loo_Mime.GetHeaderField("Content-Length")
if loo_Mime.LastMethodSuccess = 0 then
Write-Debug loo_Mime.LastErrorText
destroy loo_Mime
return
end if
Write-Debug "Content-Length: " + ls_ContentLength
destroy loo_Mime