This code is LotusScript but quite similar to VB.
'Declare Strings
Dim str_auth, str_boundary As String
'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", "https://app.streamsend.com/
uploads", 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
Question: Shoud str_fileContent be the content of name.txt in full
string?
On Dec 23, 4:01 pm, Ian Lesperance <i...@streamsend.com> wrote:
> Make sure you're sending a multipart form request and that the file contents
> are being stored in the "data" form variable.
>
> Ian
>
'Create HTTP object
Set var_submitObject = CreateObject("WinHTTP.WinHTTPRequest.5.1")
Call var_submitObject.SetTimeouts(lng_resolveTimeout,
lng_connectTimeout, lng_sendTimeout, lng_receiveTimeout)
'Set post parameters
Call var_submitObject.open(str_method, doc_profile.APIURL(0) &
str_URI, False)
Call var_submitObject.setRequestHeader("Authorization", "Basic " &
str_auth)
Call var_submitObject.setRequestHeader("Accept", "application/xml")
Call var_submitObject.setRequestHeader("Content-Type", "multipart/
form-data")
If str_contentType = "multipart/form-data" Then
str_content = "Content-Type: multipart/form-data; boundary=b1"
str_content = str_content & Chr(13) & Chr(13)
str_content = str_content & |b1|
str_content = str_content & Chr(13)
str_content = str_content & |Content-Disposition: form-data;
name="data"; filename="import.txt"|
str_content = str_content & Chr(13)
str_content = str_content & |Content-Type: text/plain|
str_content = str_content & Chr(13) & Chr(13)
str_content = str_content & |no...@none.com|
str_content = str_content & Chr(13)
str_content = str_content & |b1--|
End If
Call var_submitObject.Send(str_content)
On Jan 8, 4:00 pm, Ian Lesperance <i...@streamsend.com> wrote:
> Yes, it should be the full contents of the file. But there are a few other
> problems that I think I see:
>
> I believe the first part of str_boundary should be |b1|, not |--b1|. This
> is just a literal string, right? And b1 is your boundary string? If that's
> true, then it should be on that line by itself, with nothing before or after
> it.
>
> You need two empty lines between the multipart headers in the body and the
> content of the file. So add another Chr(13) between the |Content-Type:
> text/plain| and str_fileContent.
>
> The trailing boundary should be on a line by itself, so you'll need a
> Chr(13) between str_fileContent and |b1--|. (The trailing "--" is correct
> for the final boundary.)
>
> Ian
>
Call var_submitObject.setRequestHeader("Content-Type", "multipart/
form-data")
If str_contentType = "multipart/form-data" Then
str_content = "Content-Type: multipart/form-data; boundary=b1"
str_content = str_content & Chr(13) & Chr(13)
str_content = str_content & |b1|
If doing like you told, we receive again error 500.
'Set post parameters
Call var_submitObject.open(str_method, doc_profile.APIURL(0) &
str_URI, False)
Call var_submitObject.setRequestHeader("Authorization", "Basic " &
str_auth)
Call var_submitObject.setRequestHeader("Accept", "application/xml")
Call var_submitObject.setRequestHeader("Content-Type", "multipart/form-
data; boundary=b1")
str_content = |b1|
str_content = str_content & Chr(13)
str_content = str_content & |Content-Disposition: form-data;
name="data"; filename="import.txt"|
str_content = str_content & Chr(13)
str_content = str_content & |Content-Type: text/plain|
str_content = str_content & Chr(13) & Chr(13)
str_content = str_content & |"no...@none.com"|
str_content = str_content & Chr(13)
str_content = str_content & |b1--|
Call var_submitObject.Send(str_content)
If we declare like this (as before) then we receive error 442 (data
can't be blank):
Call var_submitObject.open(str_method, doc_profile.APIURL(0) &
str_URI, False)
Call var_submitObject.setRequestHeader("Authorization", "Basic " &
str_auth)
Call var_submitObject.setRequestHeader("Accept", "application/xml")
Call var_submitObject.setRequestHeader("Content-Type", "multipart/form-
data")
str_content = "Content-Type: multipart/form-data; boundary=b1"
str_content = str_content & Chr(13) & Chr(13)
str_content = |b1|
str_content = str_content & Chr(13)
str_content = str_content & |Content-Disposition: form-data;
name="data"; filename="import.txt"|
str_content = str_content & Chr(13)
str_content = str_content & |Content-Type: text/plain|
str_content = str_content & Chr(13) & Chr(13)
str_content = str_content & |"no...@none.com"|
str_content = str_content & Chr(13)
str_content = str_content & |b1--|
Call var_submitObject.Send(str_content)
What can we do to fix it?
Kind regards.
On Jan 14, 9:12 pm, Ian Lesperance <i...@streamsend.com> wrote:
> It looks like you're now duplicating the multipart Content-Type header in
> the body and only declaring the boundary that second time:
>
str_content = str_content & |b1|
On Jan 15, 10:43 am, Heubel <heubelm...@gmail.com> wrote:
> Hi Ian,
>
> If doing like you told, we receive again error 500.
>
> 'Set post parameters
> Call var_submitObject.open(str_method, doc_profile.APIURL(0) &
> str_URI, False)
> Call var_submitObject.setRequestHeader("Authorization", "Basic " &
> str_auth)
> Call var_submitObject.setRequestHeader("Accept", "application/xml")
> Call var_submitObject.setRequestHeader("Content-Type", "multipart/form-
> data; boundary=b1")
> str_content = |b1|
> str_content = str_content & Chr(13)
> str_content = str_content & |Content-Disposition: form-data;
> name="data"; filename="import.txt"|
> str_content = str_content & Chr(13)
> str_content = str_content & |Content-Type: text/plain|
> str_content = str_content & Chr(13) & Chr(13)
> str_content = str_content & |"n...@none.com"|
> str_content = str_content & Chr(13)
> str_content = str_content & |b1--|
> Call var_submitObject.Send(str_content)
>
> If we declare like this (as before) then we receive error 442 (data
> can't be blank):
>
> Call var_submitObject.open(str_method, doc_profile.APIURL(0) &
> str_URI, False)
> Call var_submitObject.setRequestHeader("Authorization", "Basic " &
> str_auth)
> Call var_submitObject.setRequestHeader("Accept", "application/xml")
> Call var_submitObject.setRequestHeader("Content-Type", "multipart/form-
> data")
> str_content = "Content-Type: multipart/form-data; boundary=b1"
> str_content = str_content & Chr(13) & Chr(13)
> str_content = |b1|
> str_content = str_content & Chr(13)
> str_content = str_content & |Content-Disposition: form-data;
> name="data"; filename="import.txt"|
> str_content = str_content & Chr(13)
> str_content = str_content & |Content-Type: text/plain|
> str_content = str_content & Chr(13) & Chr(13)
> str_content = str_content & |"n...@none.com"|
"As explained above, it is important that the Content-Type be
multipart/form-data. For simplicity, you may have been setting an
explicit Content-Type of application/xml on all of your other API
calls. If you were, you will need to override it (or remove it) for
this particular call. If you fail to do this, you will receive a +500+
response."
So, every value besides "multipart/form-data" will receive error 500.
But for WinHTTP library, you have to implement another condition for
the API because we have to pass the value as: "multipart/form-data;
boundary={boundary}" then the error 500 will not be presented and
things will surely start working.
On Jan 14, 9:12 pm, Ian Lesperance <i...@streamsend.com> wrote:
> It looks like you're now duplicating the multipart Content-Type header in
> the body and only declaring the boundary that second time:
>