接口传递java代码执行 java通过接口传输文件
如何用Java通过POST方法向HTTP接口传递数据
这是core java2的例子
创新互联科技有限公司专业互联网基础服务商,为您提供棕树数据中心,高防物理服务器租用,成都IDC机房托管,成都主机托管等互联网服务。
URLConnection connection = url.openConnection();//url为http服务器地址
connection.setDoOutput(true);
PrintWriter out
= new PrintWriter(connection.getOutputStream());//获得输出流
//向服务器传递参数
Enumeration enum = nameValuePairs.keys();
while (enum.hasMoreElements())
{ String name = (String)enum.nextElement();
String value = nameValuePairs.getProperty(name);
char ch;
if (enum.hasMoreElements()) ch = ''; else ch = '\n';
out.print(name + "="
+ URLEncoder.encode(value) + ch);
System.out.println(name+ value);
}
out.close();
//获取输入流
BufferedReader in;
try
{ in = new BufferedReader(new
InputStreamReader(connection.getInputStream()));
}
catch (FileNotFoundException exception)
{ InputStream err
= ((HttpURLConnection)connection).getErrorStream();
if (err == null) throw exception;
in = new BufferedReader(new InputStreamReader(err));
}
StringBuffer response = new StringBuffer();
String line;
//读取数据
while ((line = in.readLine()) != null)
response.append(line + "\n");
in.close();
return response.toString();
}
}
如何用Java通过POST方法向HTTP接口传递数据?
这是corejava2的例子\x0d\x0aURLConnectionconnection=url.openConnection();//url为http服务器地址\x0d\x0aconnection.setDoOutput(true);\x0d\x0aPrintWriterout\x0d\x0a=newPrintWriter(connection.getOutputStream());//获得输出流\x0d\x0a//向服务器传递参数\x0d\x0aEnumerationenum=nameValuePairs.keys();\x0d\x0awhile(enum.hasMoreElements())\x0d\x0a{Stringname=(String)enum.nextElement();\x0d\x0aStringvalue=nameValuePairs.getProperty(name);\x0d\x0acharch;\x0d\x0aif(enum.hasMoreElements())ch='';elsech='\n';\x0d\x0aout.print(name+"="\x0d\x0a+URLEncoder.encode(value)+ch);\x0d\x0aSystem.out.println(name+value);\x0d\x0a}\x0d\x0a\x0d\x0aout.close();\x0d\x0a//获取输入流\x0d\x0aBufferedReaderin;\x0d\x0atry\x0d\x0a{in=newBufferedReader(new\x0d\x0aInputStreamReader(connection.getInputStream()));\x0d\x0a}\x0d\x0acatch(FileNotFoundExceptionexception)\x0d\x0a{InputStreamerr\x0d\x0a=((HttpURLConnection)connection).getErrorStream();\x0d\x0aif(err==null)throwexception;\x0d\x0ain=newBufferedReader(newInputStreamReader(err));\x0d\x0a}\x0d\x0aStringBufferresponse=newStringBuffer();\x0d\x0aStringline;\x0d\x0a//读取数据\x0d\x0awhile((line=in.readLine())!=null)\x0d\x0aresponse.append(line+"\n");\x0d\x0a\x0d\x0ain.close();\x0d\x0areturnresponse.toString();\x0d\x0a}\x0d\x0a}
在Java程序里面,我想把一个接口的数据传递到下一个接口,请问应该在第一个接口的实现的类中怎么写?
按道理这样应该就可以了,如果不行你这样试试:
public
interface
MService
{
double
m(double
n1,
double
n2,
double
n3);
}
public
interface
DService
{
double
d(double
n2,
double
n3);
}
public
class
Milling
implements
MService
{
private
DService
d;
MService
ms
=
new
MService
();
d
=
ms.m(double
n1,
double
n2,
double
n3);
........
public
double
m(double
n1,
double
n2,
double
n3)
{
return
n1*40;
}
}
名称栏目:接口传递java代码执行 java通过接口传输文件
转载来于:http://hbruida.cn/article/ddcscsh.html