0

I want to send a request to an API in the below format

curl --request POST \
     --header 'Authorization: Token <token-id>' \
     --header 'Content-type: application/json' \
     --data '{"files": [{"name": "filename", "content": "xyz"}]}' \
     --url 'https://sampleurl.com'

How to do that? I've seen various questions/posts but none worked for me. P.S, I am new to Flutter.

2 Answers 2

1

Flutter makes this quite simple with the http package. Here's a basic sample:

final String url = <your-url>; 

var body = {
  "param1Key": "param1Value", 
  "param2Key": "param2Value",
  };

var headers = {"Authorization": "Token <token-id>"};
var response = await http.post(url, headers: headers, body: body);
Sign up to request clarification or add additional context in comments.

Comments

0

You need to use the http package in flutter. It provides anything you need to do networking and APIs.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.