This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.io.*; | |
import java.net.*; | |
import javax.swing.*; | |
public class Requests { | |
static String domain; | |
static URL myurl; | |
static URLConnection myurlc; | |
static OutputStreamWriter osr; | |
static BufferedReader br; | |
static String line; | |
static String resp; | |
static StringBuilder sb; | |
public Requests(String d) { | |
domain = d; | |
} | |
public String sendPost(String data) { | |
try { | |
sb = new StringBuilder(); | |
myurl = new URL(domain); | |
myurlc = myurl.openConnection(); | |
myurlc.setDoOutput(true); | |
osr = new OutputStreamWriter(myurlc.getOutputStream()); | |
osr.write(data); | |
osr.flush(); | |
br = new BufferedReader(new InputStreamReader(myurlc.getInputStream())); | |
while((line = br.readLine()) != null) | |
{ | |
sb.append(line); | |
} | |
br.close(); | |
osr.close(); | |
} | |
catch(IOException e) | |
{ | |
JOptionPane.showMessageDialog(null,"IO Error"); | |
} | |
finally { | |
return sb.toString(); | |
} | |
} | |
} |
No comments:
Post a Comment