我的xml请求如下:
<?xml version="1.0" encoding="GB2312"?>
<Spaccess_Req Ver="1.0.0">
<HDR Version="1.0.0">
<Client>
<Id>4000008</Id>
<Pwd>LBS_8263</Pwd>
</Client>
</HDR>
<!--320*250,Basemap+Include-->
<MPR>
<Output width="1024" height="768" format="image/jpg">
<BBoxContext>
<pos dimension="2">119.491 26.14623</pos>
<pos dimension="2">119.591 26.24623</pos>
</BBoxContext>
</Output>
<Basemap filter="Include">
<Layer name="AreaCoverage"></Layer>
<Layer name="Road"></Layer>
<Layer name="Highway"></Layer>
<Layer name="River"></Layer>
<Layer name="Greenbelt"></Layer>
</Basemap>
</MPR>
</Spaccess_Req>我在applet中,用一个字符串代替它:
String yinhao="\"";
request="<?xml version="+yinhao+"1.0"+yinhao+" encoding="+yinhao+"GB2312"+yinhao+"?><Spaccess_Req Ver="+yinhao+"1.0.0"+yinhao+"><HDR Version="+yinhao+"1.0.0"+yinhao+"><Client><Id>4000008</Id><Pwd>LBS_8263</Pwd></Client></HDR><!--320*250,Basemap+Include--><MPR><Output width="+yinhao+"1024"+yinhao+" height="+yinhao+"768"+yinhao+" format="+yinhao+"image/jpg"+yinhao+"><BBoxContext><pos dimension="+yinhao+"2"+yinhao+">119.491 26.14623</pos><pos dimension="+yinhao+"2"+yinhao+">119.591 26.24623</pos></BBoxContext></Output><Basemap filter="+yinhao+"Include"+yinhao+"><Layer name="+yinhao+"AreaCoverage"+yinhao+"></Layer><Layer name="+yinhao+"Road"+yinhao+"></Layer><Layer name="+yinhao+"Highway"+yinhao+"></Layer><Layer name="+yinhao+"River"+yinhao+"></Layer><Layer name="+yinhao+"Greenbelt"+yinhao+"></Layer></Basemap></MPR></Spaccess_Req>";然后,用下面的代码进行发送改请求:
try
{
URL url=new URL("http://220.200.38.21:8080/acc/localacc");
URLConnection conn=url.openConnection();
//使浏览器不缓存这个URL
conn.setUseCaches(false);
//允许接收服务器发来的数据
conn.setDoInput(true);
//允许发送数据到服务器
conn.setDoOutput(true);
String postData=URLEncoder.encode(request); ByteArrayOutputStream byteOut=new ByteArrayOutputStream(512);
//把数据写入到字节缓冲区中
PrintWriter out=new PrintWriter(byteOut);
out.println(postData);
out.flush(); String lengthString=String.valueOf(byteOut.size());
//用post请求需要设置Content-Length
conn.setRequestProperty("Content-Length",lengthString);
conn.setRequestProperty("Content-Type","application/x-www-form-urlencoded"); //用post数据连接到输出流中
byteOut.writeTo(conn.getOutputStream());
/*byte buf[]=byteOut.toByteArray();
//因为序列化的对象是用二进制数据发送的
conn.setRequestProperty("Content-type","application/octet-stream");
conn.setRequestProperty("Content-length",""+buf.length);
DataOutputStream dataOut=new DataOutputStream(conn.getOutputStream());
dataOut.write(buf);
dataOut.flush();
dataOut.close();*/
BufferedReader in=new BufferedReader(new InputStreamReader(conn.getInputStream()));
String line;
String linefeed="\r\n";
while((line=in.readLine())!=null)
{
result.append(line);
result.append(linefeed);
}
}
但运行时,却出现accessDenied(java.net.SocketPermission)的错误,是什么原因呢???怎么办呢??先谢了!!
<?xml version="1.0" encoding="GB2312"?>
<Spaccess_Req Ver="1.0.0">
<HDR Version="1.0.0">
<Client>
<Id>4000008</Id>
<Pwd>LBS_8263</Pwd>
</Client>
</HDR>
<!--320*250,Basemap+Include-->
<MPR>
<Output width="1024" height="768" format="image/jpg">
<BBoxContext>
<pos dimension="2">119.491 26.14623</pos>
<pos dimension="2">119.591 26.24623</pos>
</BBoxContext>
</Output>
<Basemap filter="Include">
<Layer name="AreaCoverage"></Layer>
<Layer name="Road"></Layer>
<Layer name="Highway"></Layer>
<Layer name="River"></Layer>
<Layer name="Greenbelt"></Layer>
</Basemap>
</MPR>
</Spaccess_Req>我在applet中,用一个字符串代替它:
String yinhao="\"";
request="<?xml version="+yinhao+"1.0"+yinhao+" encoding="+yinhao+"GB2312"+yinhao+"?><Spaccess_Req Ver="+yinhao+"1.0.0"+yinhao+"><HDR Version="+yinhao+"1.0.0"+yinhao+"><Client><Id>4000008</Id><Pwd>LBS_8263</Pwd></Client></HDR><!--320*250,Basemap+Include--><MPR><Output width="+yinhao+"1024"+yinhao+" height="+yinhao+"768"+yinhao+" format="+yinhao+"image/jpg"+yinhao+"><BBoxContext><pos dimension="+yinhao+"2"+yinhao+">119.491 26.14623</pos><pos dimension="+yinhao+"2"+yinhao+">119.591 26.24623</pos></BBoxContext></Output><Basemap filter="+yinhao+"Include"+yinhao+"><Layer name="+yinhao+"AreaCoverage"+yinhao+"></Layer><Layer name="+yinhao+"Road"+yinhao+"></Layer><Layer name="+yinhao+"Highway"+yinhao+"></Layer><Layer name="+yinhao+"River"+yinhao+"></Layer><Layer name="+yinhao+"Greenbelt"+yinhao+"></Layer></Basemap></MPR></Spaccess_Req>";然后,用下面的代码进行发送改请求:
try
{
URL url=new URL("http://220.200.38.21:8080/acc/localacc");
URLConnection conn=url.openConnection();
//使浏览器不缓存这个URL
conn.setUseCaches(false);
//允许接收服务器发来的数据
conn.setDoInput(true);
//允许发送数据到服务器
conn.setDoOutput(true);
String postData=URLEncoder.encode(request); ByteArrayOutputStream byteOut=new ByteArrayOutputStream(512);
//把数据写入到字节缓冲区中
PrintWriter out=new PrintWriter(byteOut);
out.println(postData);
out.flush(); String lengthString=String.valueOf(byteOut.size());
//用post请求需要设置Content-Length
conn.setRequestProperty("Content-Length",lengthString);
conn.setRequestProperty("Content-Type","application/x-www-form-urlencoded"); //用post数据连接到输出流中
byteOut.writeTo(conn.getOutputStream());
/*byte buf[]=byteOut.toByteArray();
//因为序列化的对象是用二进制数据发送的
conn.setRequestProperty("Content-type","application/octet-stream");
conn.setRequestProperty("Content-length",""+buf.length);
DataOutputStream dataOut=new DataOutputStream(conn.getOutputStream());
dataOut.write(buf);
dataOut.flush();
dataOut.close();*/
BufferedReader in=new BufferedReader(new InputStreamReader(conn.getInputStream()));
String line;
String linefeed="\r\n";
while((line=in.readLine())!=null)
{
result.append(line);
result.append(linefeed);
}
}
但运行时,却出现accessDenied(java.net.SocketPermission)的错误,是什么原因呢???怎么办呢??先谢了!!
解决方案 »
- org.hibernate.HibernateException: No Session found for current thread
- 请 JAVA EE 资深师傅 解答
- 关于checkboxlist选中取值的问题,
- 请教Java多线程,生产者消费者问题如何解决消费者不消费的问题
- 跪求!乱码问题
- struts2 如何拦截jsp 请求
- webservice header传用户密码
- win2003 视频聊天 无法打开摄像头
- 请教!怎样用post方式发送http报头?
- JB7+weblogic6配置完成后,运行时提示错误!!!
- 有关tomcat的配置问题。---上传无法实现应用服务。多谢各位!~
- 紧急!怎么import一个上几层文件夹中的package
permission java.net.SocketPermission "*:1024-65535", "accept,connect,listen,resolve";