public static final String POST_URL = "http://www.jiucool.com/api";
public static void poststh(String content){//content为你要拼写的XML文档字符串
URL url = null ;
try {
url = new URL(POST_URL);
} catch (MalformedURLException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
URLConnection uc = null;
OutputStreamWriter out = null;
BufferedReader rd = null;
try {
uc = url.openConnection();
uc.setDoOutput(true); //....必须设置为'true'.
uc.setRequestProperty("Content-Type", "text/xml"); //记住这行不能少否则会出错
out = new OutputStreamWriter(uc.getOutputStream(),"utf-8");
out.write(content);
out.flush();
out.close();
rd = new BufferedReader(new InputStreamReader(uc.
getInputStream(),"utf-8"));
String responseStr;
while ( (responseStr = rd.readLine()) != null) {
System.out.println("发送结果=" + responseStr);
}
rd.close();
} catch (IOException e) {
e.printStackTrace();
}
}
public static void poststh(String content){//content为你要拼写的XML文档字符串
URL url = null ;
try {
url = new URL(POST_URL);
} catch (MalformedURLException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
URLConnection uc = null;
OutputStreamWriter out = null;
BufferedReader rd = null;
try {
uc = url.openConnection();
uc.setDoOutput(true); //....必须设置为'true'.
uc.setRequestProperty("Content-Type", "text/xml"); //记住这行不能少否则会出错
out = new OutputStreamWriter(uc.getOutputStream(),"utf-8");
out.write(content);
out.flush();
out.close();
rd = new BufferedReader(new InputStreamReader(uc.
getInputStream(),"utf-8"));
String responseStr;
while ( (responseStr = rd.readLine()) != null) {
System.out.println("发送结果=" + responseStr);
}
rd.close();
} catch (IOException e) {
e.printStackTrace();
}
}