package com stroum vk Requests import java io BufferedReader import ja

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
package com.stroum.vk.Requests;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLConnection;
/**
* Created by stroum on 20.11.2014.
*/
public class Requests {
public static String post(String req_url, String params) {
try {
URL url = new URL(req_url);
URLConnection conn = url.openConnection();
conn.setDoOutput(true);
OutputStreamWriter writer = new OutputStreamWriter(conn.getOutputStream());
writer.write(params);
writer.flush();
String inputLine;
String result = "";
BufferedReader reader = new BufferedReader(new InputStreamReader(conn.getInputStream()));
while ((inputLine = reader.readLine()) != null) {
result += inputLine;
}
writer.close();
reader.close();
return result;
} catch (MalformedURLException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
return "fail";
}
}