62,620
社区成员
发帖
与我相关
我的任务
分享package com.sjy.ying;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import javax.microedition.io.Connector;
import javax.microedition.io.HttpConnection;
public class MassageSend {
String receiveuserid =null;
String senduserid =null;
String massage = null;
public void getmassagelogin(String receiveuserid, String senduserid, String massage){
this.receiveuserid = receiveuserid;
this.senduserid = senduserid;
this.massage = massage;
}
public void send() {
HttpConnection hc = null;
InputStream dis = null;
OutputStream dos = null;
// int temp = -1;
String url = "http://localhost:8080/http/http";
try {
hc = (HttpConnection) Connector.open(url, Connector.READ_WRITE);
hc.setRequestMethod(HttpConnection.POST);
hc.setRequestProperty("User-Agent",
"Profile/MIDP-1.0Configuration/CLDC-1.0");
hc.setRequestProperty("Content-Language", "en-US");
hc.setRequestProperty("Accept", "application/octet-stream");
hc.setRequestProperty("Connection", "close");
hc.setRequestProperty("Content-Length", "222");
dos = hc.openOutputStream();
} catch (IOException e) {
System.out.println("网络连接失败,请查看网络连接");
}
try {
dos.write('~');
dos.write(receiveuserid.getBytes());
dos.write(':');
dos.write(senduserid.getBytes());
dos.write('!');
dos.write(massage.getBytes());
System.out.println("wwwwwwwwwwwwwwww");
// dis = hc.openInputStream();
// StringBuffer sb = new StringBuffer();
// while ((temp = dis.read()) != -1) {
// // dos.write((char) temp);
// // System.out.print((char)temp);
// sb.append((char) temp);
// }
// temp = (char)dis.read();
// System.out.println((char)temp);
// System.out.print(temp);
// } catch (IOException e) {
// e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} finally {
try {
if (dis != null)
dis.close();
if (dos != null)
dos.close();
if (hc != null)
hc.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
}