51Testing软件测试论坛

标题: 请问数据包是流格式的怎么测试 [打印本页]

作者: zhengwl    时间: 2013-1-28 14:27
标题: 请问数据包是流格式的怎么测试
各位大侠们,有测试过数据包是流格式的吗?JAVA实现的。有没有测试这种数据包的工具呀?
下面是开发人员写的代码来测试的,有没有什么测试工具可以直接来测的?
public static void main(String[] args) throws Exception{
URL url = new URL("http://61.154.22.170:11000/FS-ECD-CLIENT/UploadServlet");
HttpURLConnection con = (HttpURLConnection)url.openConnection();
con.setRequestMethod("POST");  
con.setRequestProperty("Content-Type", "application/stream");   
con.setDoOutput(true);
con.setDoInput(true);   
con.setUseCaches(false);
con.setInstanceFollowRedirects(true);
con.connect();

File file = new File("d:" + File.separator + "ic_launcher_48.png") ;// 图片文件
InputStream in = null;
byte[] data = null;
// 读取图片字节数组
try {
in = new FileInputStream(file);
data = new byte[in.available()];
in.read(data);
in.close();
} catch (IOException e) {
e.printStackTrace();
}

DataOutputStream out = new DataOutputStream(con.getOutputStream());


out.writeUTF(sessionid);
out.writeInt(type);
out.writeUTF(timestamp);
out.writeUTF(authenticator);
out.writeInt(contactlist.size());
for (int i = 0; i < contactlist.size(); i++)
{
BasicContactStruct contactStruct = contactlist.get(i);
out.writeLong(contactStruct.contactId);
out.writeUTF(contactStruct.contactName);
out.write(contactStruct.contactPhoto);
out.writeUTF(contactStruct.sortKey);
out.writeUTF(contactStruct.groupIds);
out.writeInt(contactStruct.nativeContactId);
out.writeInt(contactStruct.flag);
}

out.writeInt(phonenumberlist.size());
for (int j = 0; j < phonenumberlist.size(); j++)
{
ContentValues values = phonenumberlist.get(j);
out.writeUTF(values.getAsString(PhoneTable.FIELD_PhoneNumber));
out.writeLong(values.getAsLong(PhoneTable.FIELD_ContactId));
out.writeInt(values.getAsInteger(PhoneTable.FIELD_PhoneType));
}

out.writeInt(grouplist.size());
for (int k = 0; k < grouplist.size(); k++)
{
ContentValues values = grouplist.get(k);
out.writeLong(values.getAsLong(GroupTable.FIELD_GroupId));
out.writeUTF(values.getAsString(GroupTable.FIELD_GroupName));
}

out.flush();
out.close();


// 发送
InputStream inputStream = con.getInputStream();


// 结果       
DataInputStream dis = new DataInputStream(inputStream);
System.out.println(dis.readInt()); //result 后面的参数依次类推

}




欢迎光临 51Testing软件测试论坛 (http://bbs.51testing.com/) Powered by Discuz! X3.2