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.

Proper way to post json with Fuel.post

See original GitHub issue

I created a list of pair and converted it to a json string. I have setted up a node server for reading the request body and the result is:

{ '{"first":"text","second":"hello"},{"first":"id","second":"djahduhdiwd"}': '' }

The whole json is interpretated as the key of the object I’m using Android with vanilla Java

List<Pair> requestParams = new ArrayList<Pair>(2);
requestParams.add( new Pair("text", "hello") );
requestParams.add( new Pair("id", "djahduhdiwd") );

String jsonString = new Gson().toJson(requestParams);

Fuel.post("http://192.168.0.90:9000/article").body(jsonString, Charset.forName("UTF-8")).responseString(new Handler<String>() {
    @Override
    public void failure(Request request, Response response, FuelError error) {}

    @Override
    public void success(Request request, Response response, String data) {
        Log.v("MainActivity", data);
    }
});

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:8 (1 by maintainers)

github_iconTop GitHub Comments

6reactions
kittinunfcommented, Mar 13, 2017

This is the snippet that I use to do POST.

val json = JSONObject()
json.put("body", "foo")

//synchronous call
val (ignoredRequest, ignoredResponse, result) =
Fuel.post("https://api.github.com/repos/cookpad/global-android/issues/${pair.second}/comments")
        .header("Authorization" to " token ${pair.first}")
        .body(json.toString())
        .responseString()

//do something with result

result.fold({ /*success*/ }, { /*failure*/ })

Can you try out and see whether you can use it like that?

5reactions
andycodesstuffcommented, Mar 5, 2017

I used Java HttpUrlConnection instead of the module

Read more comments on GitHub >

github_iconTop Results From Across the Web

Proper way to post json with Fuel.post · Issue #135 · kittinunf/fuel
I created a list of pair and converted it to a json string. I have setted up a node server for reading the...
Read more >
Kotlin - Fuel - Documentation - GitBook
HttpClient converts PATCH requests to a POST request and adds a X-HTTP-Method-Override: PATCH header. While this is a semi-standard industry ...
Read more >
Fuel HTTP Library with Kotlin - Baeldung
We can make POST requests in the same way as for GET, using httpPost() or using the post() method of the Fuel class:...
Read more >
kotlin - post request with multiple header information using fuel
Try executing that request manually. Use fiddler/postman/your preferred HTTP client. Maybe you're missing something in the body or headers?
Read more >
handeling json input::post in a rest controller - FuelPHP
Hi everybody .. What I would like is to use the data and save it into my database .. shouldn't be that difficult...
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