且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

使用Android的Jsoup将数据发送到服务器

更新时间:2023-01-01 17:00:25

如果该服务器需要一个JSON字符串,试试这个来代替:

If the server expects a JSON string, try this instead:

// Build the JSON string...
String format = "{\"feedback\":{\"q1\":%s, \"q2\":%s, \"q3\":%s, \"q4\":%s, \"q5\":%s, \"q6\":%s, \"q7\":%s, \"q8\":%s, \"q9\":%s, \"q10\":%s, \"latitude\":%s, \"longitude\":%s, \"imei\":%s, \"time\":\"%s\"}}";
String jsonData = String.format( //
           format, //
           q1, q2, q3, q4, q5, //
           q6, q7, q8, q9, q10, //
           "234", "344.4", //
           ime, time //
);

// Now send it...
Document document = Jsoup
                    .connect("http://107.170.91.100/books/save_feedback")
                    .data("JSON", jsonData) // The parameter name may not be JSON, change accordingly
                    .post();