Please Erel...POST request multipart/form-data with HttpUtils2
I must send following post request with httputils2 but i receive always
Error: Not Acceptable: Unknown or unsupported response format.
:BangHead::BangHead::BangHead:
Here Activity_Create source code:
Here sub PostMultipart
I must send following post request with httputils2 but i receive always
Error: Not Acceptable: Unknown or unsupported response format.
:BangHead::BangHead::BangHead:
HTML:
POST /restsrv/user/login HTTP/1.1
User-Agent: curl/7.28.1
Host: petforce1.com
Accept: */*
Content-Length: 258
Expect: 100-continue
Content-Type: multipart/form-data; boundary=----------------------------aa5d15c24f81
------------------------------aa5d15c24f81
Content-Disposition: form-data; name="username"
pablo
------------------------------aa5d15c24f81
Content-Disposition: form-data; name="password"
picassopwd
------------------------------aa5d15c24f81--
Here Activity_Create source code:
B4X:
Dim job2 As HttpJob
Dim NV As Map
NV.Initialize
NV.Put("username", "pablo")
NV.Put("password", "picassopwd")
'Send a POST request
job2.Initialize("Job2", Me)
job2.PostMultipart("http://www.xxxxxxxx.com/restsrv/user/login", NV, Null)
Here sub PostMultipart
B4X:
Public Sub PostMultipart(Link As String, NameValues As Map, Files As List) As HttpRequest
Dim boundary As String
Dim stream As OutputStream
Dim EOL As String
Dim b() As Byte
boundary = "------------------------------6560d8ff34d2"
stream.InitializeToBytesArray(20)
EOL = Chr(13) & Chr(10) 'CRLF constant matches Android end of line character which is chr(10).
If NameValues <> Null AND NameValues.IsInitialized Then
'Write the name/value pairs
Dim key, value As String
For i = 0 To NameValues.Size - 1
key = NameValues.GetKeyAt(i)
value = NameValues.GetValueAt(i)
b = ("--" & boundary & EOL & "Content-Disposition: form-data; name=" _
& QUOTE & key & QUOTE & EOL & EOL & value & EOL).GetBytes("UTF8")
stream.WriteBytes(b, 0, b.Length)
Next
End If
If Files <> Null AND Files.IsInitialized Then
'write the files
Dim FD As FileData
For i = 0 To Files.Size - 1
FD = Files.Get(i)
b = ("--" & boundary & EOL & "Content-Disposition: form-data; name=" _
& QUOTE & FD.KeyName & QUOTE & "; filename=" & QUOTE & FD.FileName & QUOTE _
& EOL & "Content-Type: " & EOL & FD.ContentType & EOL & EOL).GetBytes("UTF8")
stream.WriteBytes(b, 0, b.Length)
Dim In As InputStream
In = File.OpenInput(FD.Dir, FD.FileName)
File.Copy2(In, stream) 'read the file and write it to the stream
b = EOL.GetBytes("UTF8")
stream.WriteBytes(b, 0, b.Length)
Next
End If
b = (EOL & "--" & boundary & "--" & EOL).GetBytes("UTF8")
stream.WriteBytes(b, 0, b.Length)
stream.Flush
stream.Close
b = stream.ToBytesArray
Dim bc As ByteConverter
Log(bc.StringFromBytes(b,"UTF8"))
PostBytesMultipart(Link, b, boundary)
End Sub
Last edited: