cancel
Showing results for 
Search instead for 
Did you mean: 

problem with POST HTTP Header

ivo_costa
Champ in-the-making
Champ in-the-making
Hi

I've implemented a VBScript that managed to upload a file to Alfresco via IE…
It took some work but I've managed to tweak the header for  the post in order to make it work.

this is where I first got a problem… I thought that the header didn't have particular order, but the only way it worked was by setting the parameters in the right order. So… Everything right  after this quick fix

The reason for me to make such script without using forms was that I needed to do a script that could be used as an export script from ABBYYY FlexiCapture and so I added this working vbscript to that program… that's when the script stopped working again…

I've managed to generate a Basic authentication on the script(and the user gets authenticated as written in alfresco's log) but what I found that wasn't right was that once again the order of the HTTP header, but this time no matter what I did, I couldn't change the parameters order…

so what is this?? is there a particular order for the http header and flexycaptures doesn't allow me to change this in the script??? or is that not important and in this case is an alfresco bug???

please this project already late… can anybody help me?

Thanks

Ivo Costa

edit: another option would be something else is not working… and I really have a big big problem in my hands
9 REPLIES 9

wabson
Star Contributor
Star Contributor
Hi Ivo,

Could you post the contents of your VB script?

Thanks,
Will.

ivo_costa
Champ in-the-making
Champ in-the-making
Hi will

thanks for the reply

this is the test code that works from IE, unfortunately it won't work on the ocr
   dim boundaryString
   dim boundary
   dim requestbody
    dim creds
    dim Base64Encode

    creds = "admin" & ":" & "admin"





  Const adTypeText = 2
  Const adTypeBinary = 1

  'Create Stream object
  Dim BinaryStream 'As New Stream
  Set BinaryStream = CreateObject("ADODB.Stream")

  'Specify stream type - we want To save text/string data.
  BinaryStream.Type = adTypeText

  'Specify charset For the source text (unicode) data.
  BinaryStream.CharSet = "us-ascii"

  'Open the stream And write text/string data To the object
  BinaryStream.Open
  BinaryStream.WriteText creds

  'Change stream type To binary
  BinaryStream.Position = 0
  BinaryStream.Type = adTypeBinary

  'Ignore first two bytes - sign of
  BinaryStream.Position = 0

  'Open the stream And get binary data from the object
'  Stream_StringToBinary = BinaryStream.Read







    Dim dom: Set dom = CreateObject("MSXML2.DOMDocument.3.0")
    Dim elem: Set elem = dom.appendChild(dom.createElement("root"))
    elem.dataType = "bin.base64"
    elem.nodeTypedValue = BinaryStream.Read

    Base64Encode = elem.Text
   dim http_request
   Set http_request = CreateObject("Msxml2.XMLHTTP")
       Set objStream = CreateObject("ADODB.Stream")
    objStream.Type = 1
    objStream.Open
    objStream.LoadFromFile("c:\\teste.bmp")


   boundarystr = "—————————7d92a4b1705ba"
   boundary = "—————————–7d92a4b1705ba"
   requestbody = boundary & VbCrlf
   requestbody = requestbody & "Content-Disposition: form-data; name=""file""; filename=""C:\Documents and Settings\demo\Ambiente de trabalho\teste.bmp""" & VbCrlf
   requestbody = requestbody & "Content-Type: application/octet-stream" & VbCrlf & VbCrlf & escape(objStream.Read) & VbCrlf & boundary & VbCrlf
   ' "http://office.microsoft.com/pt-pt/outlook/CH101030382070.aspx" & VbCrlf & boundary & VbCrlf
   'escape(objStream.Read) & VbCrlf & boundary & VbCrlf
   requestbody = requestbody & "Content-Disposition: form-data; name=""title""" & VbCrLf & VbCrLf
   requestbody = requestbody & "txt" & VbCrLf & boundary & VbCrlf
   requestbody = requestbody & "Content-Disposition: form-data; name=""desc""" & VbCrLf & VbCrLf
   requestbody = requestbody & "site" & VbCrLf & boundary & VbCrlf
   requestbody = requestbody & "Content-Disposition: form-data; name=""submit""" & VbCrLf & VbCrLf
   requestbody = requestbody & "Upload" & VbCrLf & boundary & "–" & VbCrLf
   
   http_request.open "POST", "http://10.0.0.13:8080/alfresco/service/sample/upload", true

   http_request.setRequestHeader "Accept", "image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, application/x-shockwave-flash, application/vnd.ms-excel, application/vnd.ms-powerpoint, application/msword, */*"
   http_request.setRequestHeader "Content-length", len(requestbody)
   http_request.setRequestHeader "Connection", "Keep-Alive"
   http_request.setRequestHeader "Content-type", "multipart/form-data; boundary=" & boundarystr
        http_request.setRequestHeader "Authorization", "Basic " & Base64Encode
   

   
   http_request.send requestbody

package trace reveals that the header is the only thing that changes for both tests (properties change order but not content)

wabson
Star Contributor
Star Contributor
Hi ivo,

Can you also post the HTTP request and the response from your packet trace both with IE and with the OCR software?

Thanks,
Will.

ivo_costa
Champ in-the-making
Champ in-the-making
Hi Will

after a few tests I came to reproduce the same header from OCR with IE and the webscript ran exactly like I wanted, so the problem as to be something with how the OCR creates (or not) the next packages just after the header… I'lll check that out…

I'm not an expert on http post, but so far what I got is that the header is semi-rigid and so I was stumbling in two problems maybe

ivo_costa
Champ in-the-making
Champ in-the-making
Hi

I've managed to develop what I needed by applying 2 webscripts, one using put to upload the file and return the noderef and one another that using the noderef puts the values into the properties.

If anyone interested I can give a hand on that

Thanks

lista
Star Contributor
Star Contributor
Someone will face the same or similar issue sooner or later.
So I suggest that you posts as much as you can about the problem.  Smiley Happy

wabson
Star Contributor
Star Contributor
Ivo,

As Lista says, you need to post as much information about your issues so that other users on the forums can help you. This includes all relevant source code that you have developed, the results you expect to see and what actually happens. From the latest information you provide, it is very difficult to understand what your problem is, let alone help to fix it.

Thanks,
Will.

ivo_costa
Champ in-the-making
Champ in-the-making
Hi

I was trying to get ABBYY Flexicapture so export a Image file along with the relevant data

at first I was trying to reproduce a multi-part form POST, but for this to work one would have to reproduce the POST structure in a way that meta-data and files would get sent side-by-side using only a one-time connection.

unfortunately this is a bigger problem than it is a solution… after reproducing all the header parts and making the data string, you'd get a "request no valid" or something like that (this indeed worked in IE, but not from inside Flexicapture for some reason)… Later I'd have a bigger problem (how to get the file to be sent with the right encoding and not the messed up chars I was recieving inside Alfresco… 0x7F for some reason would change to something else)

So… after hours of fighting this thing and almost knocked-out by some kind of left-hook on a 10th round, I've decided to use multiple webscripts for each step I'd need to do.

So now I have a PUT webscript that recieves the file and returns a nodeRef, and a GET webscript that recieves the noderef and the needed meta-data.
This is not the best solution, as I need to send 2 files (1 image, and 1 text) with the same meta-data… but at least it works

WARNING: Never ever ever, forget to escape(string) the meta-data you're trying to send through a GET request… It will make you pull your hairs out to figure what is making your webscript fail

as soon as I've completed what is left to do with this thing I'll post some of the code

thanks

ivo_costa
Champ in-the-making
Champ in-the-making
As promissed a long long time ago, in a place not that far

heres a sample of the exporting script

    fileName = fso.BuildPath(folderName, justfile & ".txt")

    Set txtFile = fso.CreateTextFile(fileName, True)
    txtFile.WriteLine "Empresa: " & me.Field( "Section1\Company" ).Value
    txtFile.WriteLine "Contribuinte Externo: " & me.Field( "Section1\VatID" ).Value
    txtFile.WriteLine "Data de Emissão: " & me.Field( "Section1\Date" ).Value
    txtFile.WriteLine "Numero de Factura: " & me.Field( "Section1\InvoiceNumber" ).Value
    txtFile.WriteLine "Total: " & me.Field( "Section1\Total" ).Value
    txtFile.Close

    set objStream = Nothing

    Set objStream = CreateObject("ADODB.Stream")
    objStream.Type = 1
    objStream.Open
    objStream.LoadFromFile(fileName)



    set oXMLHttp = CreateObject("microsoft.xmlhttp")
   
    If sUserName <> "" Then
        oXMLHttp.Open "PUT", sHREF, False, sUserName, sPassword   
    Else
         oXMLHttp.Open "PUT", sHREF, False ', sUserName, sPassword   
    End If
   


    oXMLHttp.setRequestHeader "translate", "f" ' Set this to prevent stream problems
    oXMLHttp.Send objStream.Read ' Send the stream across
    nodeRef = oXMLHttp.responsetext

        oXMLHttp.Open "GET", sHREF & "?noderef=" & nodeRef & "&name="& newname & ".txt" & "&description=factura&cont=" & escape(vatid) & "&value=" & escape(total) & "&date=" & escape(date) & "&number=" & escape(invoicenumber) & "&company=" & escape(company), false
    oXMLHttp.Send

It took a while … too much work Smiley Sad