Answer the question
In order to leave comments, you need to log in
How to make a POST request in Android using JSoup or similar library/function?
Hello, I am new to Android programming. Now I'm trying to make a small application that will change the user's mood in the Ya.ru social network. According to the page from the API, you need to create a request like this:
POST /person/{uid}/post/ HTTP/1.1
Host: api-yaru.yandex.ru
Content-Type: application/atom+xml; type=entry; charset=utf-8
Content-Length: 199
Authorization: OAuth vF9dft4qmT
<entry xmlns="http://www.w3.org/2005/Atom" xmlns:y="http://api.yandex.ru/yaru/">
<category scheme="urn:ya.ru:posttypes" term="status"/>
<content>Новый статус</content>
<y:comments_disabled/>
</entry>
Connection.Response res = Jsoup.connect(src.attr("href")+"?oauth_token="+Main.getToken()).method(Method.POST).execute();
Answer the question
In order to leave comments, you need to log in
jsoup.org/apidocs
org.jsoup
Interface Connection
To get a new Connection, use Jsoup.connect(String).
header(String name, String value)
Set a request header.
data(String key, String value)
Add a request data parameter.
method(Connection.Method method)
Set the request method to use, GET or POST.
try {
Connection conn = Jsoup
.connect("http://4pda.ru/forum/index.php?act=Login&CODE=01");
conn.data("PassWord", "password");
conn.data("UserName", "username");
conn.method(Connection.Method.POST);
conn.referrer("http%3A%2F%2F4pda.ru%2Fforum%2Findex.php%3F");
Response resp = conn.execute();
System.out.println("statusCode: " + resp.statusCode());
Document doc = conn.url("http://4pda.ru/forum/index.php?").get();
System.out.println(doc.select("div.user_home").text());
} catch (IOException e) {
e.printStackTrace();
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question