httr icon indicating copy to clipboard operation
httr copied to clipboard

Control programs based on httr to print the raw requests

Open prRZ5F4LXZ opened this issue 2 years ago • 1 comments

I want to let httr print debug messages (e.g., the request sent and the request received). But I don't find such an option.

In python-requests, the way is like this. If something similar to this is not possible with httr, should a similar control be added to httr so the debug messages can be turned on/off outside of the program that calls httr?

>>> import requests
>>> import logging
>>> logging.basicConfig(level=logging.DEBUG)
>>> import http.client
>>> http.client.HTTPConnection.debuglevel=1
>>>
>>> r = requests.post('http://httpbin.org/post'
...             , headers = {'h1': 'v1'}
...             , data = {'key': 'value'}
...             )
DEBUG:urllib3.connectionpool:Starting new HTTP connection (1): httpbin.org:80
send: b'POST /post HTTP/1.1\r\nHost: httpbin.org\r\nUser-Agent: python-requests/2.25.1\r\nAccept-Encoding: gzip, deflate\r\nAccept: */*\r\nConnection: keep-alive\r\nh1: v1\r\nContent-Length: 9\r\nContent-Type: application/x-www-form-urlencoded\r\n\r\n'
send: b'key=value'
reply: 'HTTP/1.1 200 OK\r\n'
header: Date: Fri, 16 Jul 2021 00:41:02 GMT
header: Content-Type: application/json
header: Content-Length: 495
header: Connection: keep-alive
header: Server: gunicorn/19.9.0
header: Access-Control-Allow-Origin: *
header: Access-Control-Allow-Credentials: true
DEBUG:urllib3.connectionpool:http://httpbin.org:80 "POST /post HTTP/1.1" 200 495

prRZ5F4LXZ avatar Jul 16 '21 00:07 prRZ5F4LXZ

Have a look at httr::with_verbose():

https://httr.r-lib.org/reference/with_config.html

jennybc avatar Jul 16 '21 01:07 jennybc