question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Sending Post Request.

See original GitHub issue

Hello, I would like to send a simple post request in order to create a new project with a given project name. First try:

URL = 'http://localhost:8080/api/v2/projects'
dataa={
  "messages": [],
  "body": {
    "name": "Dummy_Name2"
  }
}

r = requests.post(URL, data = dataa,auth=('admin', 'admin'))

Output:

{'timestamp': 1528204046959, 'status': 415, 'error': 'Unsupported Media Type', 'exception': 'org.springframework.web.HttpMediaTypeNotSupportedException', 'message': "Content type 'application/x-www-form-urlencoded' not supported", 'path': '/api/v2/projects'}

Any opinion is appreciated.

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:8 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
reckartcommented, Jun 5, 2018

The Content-Type header needs to specify a multipart boundary, e.g.

curl -u username:password -X POST --header 'Content-Type: multipart/form-data; boundary=---multipart-boundary-RANDOMSTRING' --header 'Accept: application/json' 'http://localhost:8080/webanno-webapp/api/v2/projects?name=test'

then you get sensible output:

{"messages":[],"body":{"id":260,"name":"test"}}
0reactions
rbhambriiitcommented, Dec 3, 2018

Working Python solution:

import requests
project_name = 'api_project1'
create_project_url = "http://??.??.???:?????/api/v2/projects?name=" + project_name
headers = { "content-type": "multipart/form-data; boundary=---multipart-boundary-RANDOMSTRING" }
response = requests.post(create_project_url, auth=('???', '???'), headers=headers)
create_project = response.json()

Read more comments on GitHub >

github_iconTop Results From Across the Web

How do I send an POST request? - ReqBin
The HTTP POST request method is used to send data to the server or create or update a resource. The POST request is...
Read more >
How to manually send HTTP POST requests from Firefox or ...
The simplicity of pressing F12 , write the command in the console tab (or press the up key if you used it before)...
Read more >
POST - HTTP - MDN Web Docs
The HTTP POST method sends data to the server. The type of the body of the request is indicated by the Content-Type header....
Read more >
Python Requests post Method - W3Schools
The post() method sends a POST request to the specified url. The post() method is used when you want to send some data...
Read more >
HTTP | Part 4: HTTP POST Request - YouTube
HTTP - Module 4/5 In this video, you will see an example of how you can use the HTTP app inside Integromat in...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found