GET request working through Python but not through Postman

 ̄綄美尐妖づ 提交于 2021-01-28 06:33:48

问题


I am trying to use the Mailman 3 REST API, but I need to call it from Spring's Rest Template in a java class, or for testing purpose from Postman. In Python, I can call the API by:

>>> from httplib2 import Http
>>> headers = {
...     'Content-Type': 'application/x-www-form-urlencode',
...     'Authorization': 'Basic cmVzdGFkbWluOnJlc3RwYXNz',
...     }
>>> url = 'http://localhost:8001/3.0/domains'
>>> response, content = Http().request(url, 'GET', None, headers)
>>> print(response.status)
200

I want to make the same request, but through Postman. For that, I have used the URL "http://127.0.0.1:8001/3.0/domains". I have added 2 fields in the headers, the preview looks like:

GET /3.0/lists HTTP/1.1
Host: 127.0.0.1:8001
Content-Type: application/x-form-urlencode
Authorization: Basic cmVzdGFkbWluOnJlc3RwYXNz
Cache-Control: no-cache
Content-Type: application/x-www-form-urlencoded

But the request status only shows "pending" and I receive no response. Mailman is running on a python virtualenv.

I am also trying to run the following command in my terminal:

curl --header "Content-Type: application/x-form-urlencoded, Authorization: Basic cmVzdGFkbWluOnJlc3RwYXNz" http://localhost:8001/3.0/domains

But the output is:

{
    "title": "401 Unauthorized",
    "description": "The REST API requires authentication"
}

I am stuck at this point, because I do not wish to use Mailman's Web UI postorius, but wish to call the REST API from java class. I would also like to know, if I am making a particular mistake in forming my Postman request, but how can I do the same using Spring's Rest Template.

Any help would be appreciated. Thank you


回答1:


To fix curl command, use the -H parameter seperately.

curl -H "Content-Type: application/x-form-urlencoded" -H "Authorization: Basic cmVzdGFkbWluOnJlc3RwYXNz" http://localhost:8001/3.0/domains


来源:https://stackoverflow.com/questions/36052940/get-request-working-through-python-but-not-through-postman

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!