Require help with myHTTP please =)

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • mandanarchi
    New Member
    • Sep 2008
    • 90

    Require help with myHTTP please =)

    Code:
    Sub test()
    Dim myHTTP As MSXML2.xmlhttp                     
    Dim myDom As MSXML2.DOMDocument                  
    Dim orderno, errormsg, lineerr, lineerrmsg As MSXML2.IXMLDOMNode      
    Dim myxml As String
    
    boundary = "-----------------------------29772313742745"
    
    
    myxml = "--" & boundary & vbCrLf &  _
    "<?xml version=""1.0"" encoding=""UTF-8""?>" & _
    "<OnlineCheck>" & _
    "<Header>" & _
    "<BuyerAccountId></BuyerAccountId>" & _
    "<AuthCode></AuthCode>" & _
    "<Type>Full</Type>" & _
    "</Header>" & _
    "<Item line=""1"">" & _
    "<ManufacturerItemIdentifier/>" & _
    "<DistributorItemIdentifier>1088963</DistributorItemIdentifier>" & _
    "<Quantity>1</Quantity>" & _
    "</Item>" & _
    "</OnlineCheck>" & vbCrLf & vbCrLf & boundary & "--"
    
    Set myHTTP = CreateObject("msxml2.xmlhttp")
    Set myDom = CreateObject("MSXML2.DOMDocument")
    myDom.async = False
    myDom.Load (myxml)
    myHTTP.Open "POST", "", False
    myHTTP.setRequestHeader "Content-Type", "multipart/form-data; boundary=" & boundary
    myHTTP.setRequestHeader "Content-Disposition", "form-data; name=""xmlmsg"""
    myHTTP.setRequestHeader "Content-Length", Len(myxml)
    
    myHTTP.send (myDom.xml)
    
    MsgBox myHTTP.responseText
    
    End Sub
    Can anyone spot anything obviously wrong with this code?

    M'kay.
    I have to send the xml (myxml) to a website via POST.
    It has to be multipart/form-data, and has to have a name of 'xmlmsg'.
    Don't ask me why, it's the way they've set it up.

    I have the exact same code working for another of our suppliers; with the one difference being the setRequestHeade r lines. None of our other suppliers require these; which leads me to think that's the problem.

    When I ommit all the headers, I get a message saying basically 'wrong format, form name must be xmlmsg'. When I add the content-type header, this changes to <error>-3</error>.
    I know, helpful right?
    The company doesn't know what the error means, and haven't got an error code list. I don't know what's happened to whoever set the system up for them.

    We use Access2003 and I'd prefer not to have to make a webpage to do this.

    Thanks for any help/guidance you can give =)

    Mandi
  • mandanarchi
    New Member
    • Sep 2008
    • 90

    #2
    I've tried the code without the boundarys in 'myxml'.
    I've tried it with the headers declared in the posted data rather than using setRequestHeade rs.
    I've tried everything I can think of and I swear I'm just going backwards.


    I think I just need to set the name to xmlmsg, but I can't figure out how.
    I know in html it would be <form name="xmlmsg"> but in vba....

    I've tried
    Code:
    SetRequestHeader="Content-Disposition", "form-data: name=""xmlmsg"""
    SetRequestHeader="Content-Disposition", "name=""xmlmsg"""
    SetRequestHeader="Content-Disposition", "name='xmlmsg'"
    SetRequestHeader="Content-Disposition", "name=xmlmsg"
    SetRequestHeader="ContentDisposition", "name=""xmlmsg"""
    SetRequestHeader="name", "xmlmsg"
    (Not all at once though, obviously)

    Nothing seems to work.

    Does anyone know how to set that?

    Thanks
    Mandi

    Comment

    • Stewart Ross
      Recognized Expert Moderator Specialist
      • Feb 2008
      • 2545

      #3
      I suspect you are trying the wrong property here; I think CONTENT-TYPE would be more appropriate, since it is this standard header that can be used to specify that the content is a multi-part form. However, this is not my specialist area at all (or the Access forum's). Would you prefer your post to be moved to the HTML forum for a more considered view?

      In the meantime you may wish to look up the following references to the standard headers and their meanings:

      http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html (look up CONTENT-TYPE)
      http://www.w3.org/Protocols/rfc2616/...c3.html#sec3.7 (look up Multipart Types)


      -Stewart

      Comment

      • mandanarchi
        New Member
        • Sep 2008
        • 90

        #4
        Originally posted by Stewart Ross Inverness
        I suspect you are trying the wrong property here; I think CONTENT-TYPE would be more appropriate,
        -Stewart
        Thanks for the reply.
        I'm using content type too; and I know that one works as when I don't use it I get an error about using the wrong type. When I do use it, I just get -3.

        Because I didn't get a reply in over a week, I started a similar thread in the HTML forums in case they knew anything more. But to be quite honest, I'm not sure who I should be asking about this.

        I'm getting frustrated by this so I think I'll let it lie for a while and do something else. Knowing my luck it'll end up being something really obvious that I've over looked because I've been overthinking it.

        Mandi

        Comment

        Working...