Created
December 19, 2010 02:30
-
-
Save eggie5/747051 to your computer and use it in GitHub Desktop.
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
private void sendpic(String data_string) { | |
try { | |
String xmldata = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" | |
+ "<photo><photo>" + data_string + "</photo></photo>"; | |
// Create socket | |
String hostname = "http://eggie5.com"; | |
String path = "/a"; | |
int port = 80; | |
InetAddress addr = InetAddress.getByName(hostname); | |
Socket sock = new Socket(addr, port); | |
// Send header | |
BufferedWriter wr = new BufferedWriter(new OutputStreamWriter( | |
sock.getOutputStream(), "UTF-8")); | |
wr.write("POST " + path + " HTTP/1.1\r\n"); | |
wr.write("Host: eggie5.com\r\n"); | |
wr.write("Content-Length: " + xmldata.length() + "\r\n"); | |
wr.write("Content-Type: text/xml; charset=\"utf-8\"\r\n"); | |
wr.write("Accept: text/xml\r\n"); | |
wr.write("\r\n"); | |
// Send data | |
wr.write(xmldata); | |
wr.flush(); | |
// Response | |
BufferedReader rd = new BufferedReader(new InputStreamReader( | |
sock.getInputStream())); | |
String line; | |
while ((line = rd.readLine()) != null) { | |
Log.v("eggie5", line); | |
System.out.println(line); | |
} | |
} catch (Exception e) { | |
e.printStackTrace(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment