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.

how to send data use http get method

See original GitHub issue

I want to send params and data use http get methods

I want get http params and data at backend. Example Code

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>vue get send data demo</title>
</head>
<body>
<div id="app">
    this is app info: {{info}}
</div>

<script src="https://cdn.staticfile.org/axios/0.18.0/axios.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/vue@2.5.16/dist/vue.js"></script>
<script>
data = {"name": "danerlt", "age": 23}
index = 1
count = 15
url = `http://localhost:5000/get_body?index=${index}&count=${count}`
console.log(url)
console.log(data)
new Vue({
  el: '#app',
  data () {
    return {
      info: null
    }
  },
  mounted () {
    axios.get(url, body=data).then(response => (this.info = response))
  }
})

</script>
</body>
</html>

my backend code use python flask

# -*- coding: utf-8 -*-

import json
from flask import Flask, request, jsonify
from flask_cors import CORS
app = Flask(__name__)

CORS(app, resources=r'/*')


@app.route('/get_body', methods=["GET"])
def get_http_body():
    args = request.args
    print('get_http_body args: %s' % [args])
    try:
        body = request.data.decode()
        print('get_http_body body: %s' % body)
        # data = json.loads(body)
    except Exception as e:
        print(e)
        return jsonify(status='error', msg=str(e))
    else:
        return jsonify(status='ok', data=body)

Environment:

  • Axios Version 0.18.0
  • OS: Windows 10
  • Browser : Chrome

Additional context/Screenshots In my python code, the http data is empty string, When I use poseman like this: image It return the right result, How can I resove this probleam?

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:8

github_iconTop GitHub Comments

1reaction
chinesedfancommented, Dec 10, 2019

mounted () { axios.get(url, body=data).then(response => (this.info = response)) }

Try axios.get(url, { params: data } instead of above usage.

0reactions
chinesedfancommented, Dec 10, 2019

@danerlt 通过一些网上的查找,准确的描述见更新后的https://github.com/axios/axios/issues/2598#issuecomment-563965172.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to send data in request body with a GET when using ...
1.GET use of Query string as. {{url}}admin/recordings/some_id ; here the some_id is mendatory parameter to send and can be used and req.params.some_id at...
Read more >
HTTP Methods GET vs POST - W3Schools
The two most common HTTP methods are: GET and POST. The GET Method. GET is used to request data from a specified resource....
Read more >
How do I send an HTTP GET request? - ReqBin
The GET request method is used to fetch data from the server. We cannot send data in the body of an HTTP GET...
Read more >
GET - HTTP - MDN Web Docs
The HTTP GET method requests a representation of the specified resource. Requests using GET should only be used to request data (they ...
Read more >
HTTP Request Methods – Get vs Put vs Post Explained with ...
PUT requests are idempotent, meaning that executing the same PUT request will always produce the same result. On the other hand, a POST...
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