0

yI'm using the {httr} package to log into an internal web application (Theradoc on IIS7.5) in order to scrape some html (infection) data.

library(httr)
POST("http://ahdc372n2", authenticate("foo", "bar"), encode="multipart"), verbose())

The verbose console output says,

-> POST /theradoc/login/index.cfm HTTP/1.1
-> Authorization: Basic Y2xpbmludGVsbDowMWRFbmdsaXNo
-> User-Agent: curl/7.19.6 Rcurl/1.95.4.3 httr/0.4
-> Host: ahdc372n2.phs-sfalls.amck.net
-> Accept: */*
-> Accept-Encoding: gzip
-> Cookie: JSESSIONID=843052421c871dec2ac3a263b136d475a4a6
-> 
<- HTTP/1.1 411 Length Required
<- Content-Type: text/html; charset=us-ascii
<- Server: Microsoft-HTTPAPI/2.0
<- Date: Mon, 08 Sep 2014 15:53:02 GMT
<- Connection: close
<- Content-Length: 344
<- 
*  Closing connection #0

And ultimately I get an ">HTTP Error 411. The request must be chunked or have a content length."

I've reviewed this older post without and useful pointers.

Is there a way to force the Content-Length in the httr POST request?

Community
  • 1
  • 1
Colin
  • 930
  • 3
  • 19
  • 42
  • You can see the content-related functions in httr using `ls("package:httr", pattern = "content")`. I can't see anything in the help pages about forcing content length, but they may be helpful to you. – Richie Cotton Sep 08 '14 at 16:13
  • Thanks Richie. I guess I should try use package RCurl then. I think you've probably answered this question then... If you'd like to make it as an answer, I'll accept it. Don't suppose you could give me the RCurl equivalent as part of the answer (me just being lazy:)? – Colin Sep 08 '14 at 16:20
  • Can you also do this request in Chrome or something where you can see all the headers present when the request works? I wonder if you need to add something else to the accept header. I wish there was someway to reproduce the environment to test what's happening. – MrFlick Sep 08 '14 at 16:29
  • Are you really not posting any data in your post request? – MrFlick Sep 08 '14 at 16:30
  • 1
    Have you tried it with `httr` 0.5? (recently released) – hrbrmstr Sep 08 '14 at 17:09
  • I tested using `httr_0.4` with `POST("http://requestb.in/????", authenticate("foo", "bar"), body=character(), encode="multipart", verbose())` where `????` was the unique ID given by `http://requestb.in`. The verbose output showed content length and the request the server received had a content-length header. What version of `httr` are you using (you can tell with `sessionInfo()`). You could also try explicitly setting `body=character()` to indicate no body content. – MrFlick Sep 08 '14 at 17:21

1 Answers1

0

UPDATE : Manually installing httr_0.5 from the zip archive seems to have solved the problem. Thank you hrbmstr.

Community
  • 1
  • 1
Colin
  • 930
  • 3
  • 19
  • 42