Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/loops/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Web services 在Restful Web服务中传递参数_Web Services_Rest_Get - Fatal编程技术网

Web services 在Restful Web服务中传递参数

Web services 在Restful Web服务中传递参数,web-services,rest,get,Web Services,Rest,Get,亲爱的Stackoverflow用户:, 我已经在RESTfulWebService上玩了很长时间了。 我对如何使用GET方法传递参数有点怀疑。 由于get只能用于检索任何资源,所以如何传递参数。 我已经为此编写了一个小代码,但代码似乎有问题 @GET @Produces("text/plain") @Path("/instrumentname/") public String getname(String name1) { try { String [] env=n

亲爱的Stackoverflow用户:, 我已经在RESTfulWebService上玩了很长时间了。 我对如何使用GET方法传递参数有点怀疑。 由于get只能用于检索任何资源,所以如何传递参数。 我已经为此编写了一个小代码,但代码似乎有问题

@GET
    @Produces("text/plain")
    @Path("/instrumentname/")
    public String getname(String name1) {
try {


String [] env=null;
            String[]callAndArgs= {"python","connection.py",ins_name};//passing the parameters

            Process p = Runtime.getRuntime().exec(callAndArgs,env,
                    new java.io.File("C:\\Users\\Balkishore\\Documents\\NetBeansProjects\\Testinstrument_Rest\\build\\web"));//excuting the python file



            BufferedReader stdInput = new BufferedReader(new 

                 InputStreamReader(p.getInputStream()));//getting the input



            BufferedReader stdError = new BufferedReader(new 

                 InputStreamReader(p.getErrorStream()));//getting the error




           interface_name = stdInput.readLine();//reading the output




                System.out.println(interface_name);


    }


        catch (IOException e) {//catching the exception

            System.out.println("exception occured");

            e.printStackTrace();

            System.exit(-1);

        }
        return this.interface_name;
    } 
任何帮助都将不胜感激。 非常感谢。
干杯

您只需将URL末尾的参数以以下格式连接起来: www.xyz.com/?param1=val1¶m2=val2¶m3=val3

其中param1,param2是参数名,val1,val2是对应参数的值。。。您只需在浏览器的URL栏中键入它们,而无需编写HTML页面或用于测试的脚本


另外,GET通常用于从web服务器获取资源,这一说法是正确的,但有时您必须传递必须获取其资源的信息…

谢谢您的回复,mate!!但是,如果我有一个与服务器链接的java客户机呢?在这种情况下,我无法通过URL传递参数。我必须知道如何将参数嵌入我的GET方法,对吗?如果不是,在上面的代码中可以做些什么来传递参数?非常感谢您的帮助。提前谢谢。还有一件事我没有使用任何类型的数据库。这个代码是服务器端代码,对吗??现在您想知道如何将参数从客户端传递到服务器吗??或者您想知道如何将此函数中的参数传递给作为shell命令调用的python脚本??我想知道如何将此函数中的参数传递给python脚本。感谢mate的回复。如果我知道这一点,我还可以将参数从服务器传递到java Jframe客户端。顺便说一下,是的,它是服务器端代码匹配。您可以使用@Queryparam注释来读取url参数。如果这是你正在寻找的,请参考。