1
'Declare long
Dim lng_resolveTimeout, lng_connectTimeout, lng_sendTimeout,
lng_receiveTimeout As Long

'Declare integer
Dim int_serverCredentials As Integer

'Declare variants
Dim var_submitObject As Variant

'Set values
int_serverCredentials = 0

lng_resolveTimeout = 120000 'miliseconds = 2 minutes
lng_connectTimeout = 1200000
lng_sendTimeout = 1200000
lng_receiveTimeout = 1200000

'Create HTTP object
Set var_submitObject = CreateObject("WinHTTP.WinHTTPRequest.5.1")
Call var_submitObject.SetTimeouts(lng_resolveTimeout,
lng_connectTimeout, lng_sendTimeout, lng_receiveTimeout)

'Standards for this post
%REM
Content-Type: multipart/form-data; boundary={boundary}
{boundary}
Content-Disposition: form-data; name="data"; filename="{filename}"
Content-Type: text/plain
{contents}
{boundary}--
%END REM

'Set post parameters
Call var_submitObject.open("POST", str_url, False)
Call var_submitObject.setRequestHeader("Accept", "application/xml")
Call var_submitObject.setRequestHeader("Authorization", "Basic " & str_auth)
Call var_submitObject.setRequestHeader("Content-Type", "multipart/form-data; boundary=b1")
str_boundary = |--b1| & Chr(13) &_
|Content-Disposition: form-data; name="data"; filename="name.txt"| & Chr(13) &_
|Content-Type: text/plain| & Chr(13) &_
str_fileContent & |b1--|
'Send the HTTP request
Call var_submitObject.Send(str_boundary)
'Wait for the answer and set object as returned value for further validation
Call var_submitObject.WaitForResponse
Set submitHTTP = var_submitObject
'Clear memory
Set var_submitObject = Nothing

问题: 1)如何指定“边界”并将文件内容正确发送为TXT文件上传?2)如何为这个边界内容指定换行符?

亲切的问候,提前!

4

1 回答 1

1

关于 EOL 问题,您指定Chr(13)了但这不是 Windows 中的完整换行符(我假设您使用的是基于您还提到的 winhttp 标记的 Windows)。Windows 中的 EOL 实体是CR + LF回车符是 Chr(13),换行符是 Chr(10)。

关于文本,您在内容类型中指定。

于 2010-02-25T12:13:29.933 回答