Question

Although I have created a header dictionary to pass to the POST method below, I am getting extra text in the XML POST body of my request. I can see that the file I have created is getting to its destination and that the authorization headers are good. (The server is returning a "bad XML" error rather than a 404 or 401, so I know the request got there OK.) The XML itself is fine, so the problem is with the header text being added to the payload.

How can I get RobotFramework to send only my XML payload?

Thanks

RobotFramework request

${result}=  RequestsLibrary.POST  my_session  ${requestURL}  headers=${headers}  files=${fileDictionary}

Extra text add to prologue of POST body that causes the XML parser to choke. Alphanumeric string at the start and end along with extra header values.

--02f79864e37a402e8f70425edb9a9790
Content-Disposition: form-data; name="file1"; filename="file1"
Content-Type: application/octet-stream
<!-- XML Body -->
--02f79864e37a402e8f70425edb9a9790--
Was it helpful?

Solution

PEBKAC: Reader failed to parse documentation. First thing is that I should have been passing data= and not files= in this call. Second, I misunderstood the following statement in the docs for RequestsLibrary:

data a dictionary of key-value pairs that will be urlencoded and sent as POST data or binary data that is sent as the raw body content

Specifically, I didn't apply the word "or" to the right phrases. Just in case someone else missed it too, it's "(A dictionary of key-values pairs...) OR (binary data)." NOT "A dictionary of key-value pairs or (a dictionary of) binary data."

I was going nuts trying to figure out why you'd use a dictionary of binary data. Too much time in strongly typed languages I guess. The key is that you can pass a dictionary when your POST data is something like form data, or you can pass a string (which you may wish to assign via the OperatingSytem Get File command). Once I realized I should be passing just a string value, all was right in the world.

Thanks to Bulkan for setting me straight.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top