[英]Send string to a http server with JAVA
try {
URL url = new URL("ftp://username:password@url.net/FileToWrite.txt");
URLConnection urlc = url.openConnection();
OutputStream os = urlc.getOutputStream();
OutputStream buffer = new BufferedOutputStream(os);
ObjectOutput output = new ObjectOutputStream(buffer);
output.writeChars("hello");
buffer.close();
os.close();
output.close();
} catch (IOException e) {
System.out.println(e);
}
此代碼給了我一個套接字異常,請幫助我迷路
這在Java 8中對我有用:
try {
URL url = new URL("http://cnn.com"); /* Tested on a real URL */
URLConnection urlc = url.openConnection();
urlc.setDoOutput(true); /* Added this ... */
OutputStream os = urlc.getOutputStream();
OutputStream buffer = new BufferedOutputStream(os);
ObjectOutput output = new ObjectOutputStream(buffer);
output.writeChars("hello");
buffer.close();
os.close();
output.close();
System.out.println("Done");
} catch (IOException e) {
e.printStackTrace();
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.