Post request using cookies with cURL, RCurl and httr

后端 未结 3 673
陌清茗
陌清茗 2021-02-06 16:23

In Windows cURL I can post a web request similar to this:

curl  --dump-header cook.txt ^
  --data \"RURL=http=//www.example.com/r&user=bob&password=hell         


        
3条回答
  •  一整个雨季
    2021-02-06 16:48

    httr automatically preserves cookies across calls to the same site, as illustrated by these two calls to http://httpbin.org

    GET("http://httpbin.org/cookies/set?a=1")
    # Response [http://httpbin.org/cookies]
    #   Status: 200
    #   Content-type: application/json
    # {
    #    "cookies": {
    #     "a": "1"
    #   }
    # } 
    
    GET("http://httpbin.org/cookies")
    # Response [http://httpbin.org/cookies]
    #   Status: 200
    #   Content-type: application/json
    # {
    #   "cookies": {
    #     "a": "1"
    #   }
    # } 
    

    Perhaps the problem is that you're sending your data as application/x-www-form-urlencoded, but the default in httr is multipart/form-data, so use multipart = FALSE in your POST call.

提交回复
热议问题