简体   繁体   English

我可以将Web服务称为HTTP请求吗?

[英]can i call web service as a HTTP request?

I have some limitations in using generated stubs with the 3rd party software. 在使用第三方软件生成的存根时,我有一些限制。 SO, I am looking for other options like simple HTTP request and response to get the result. 因此,我正在寻找其他选项,例如简单的HTTP请求和响应以获取结果。 I will probably need to pass 5 or 6 parameters to one operation and get one output from the web service. 我可能需要将5或6个参数传递给一个操作,并从Web服务获取一个输出。

I can create a simple JSP file, which internally calls the webservice. 我可以创建一个简单的JSP文件,该文件在内部调用Web服务。 I can call this JSP via HTTP Request. 我可以通过HTTP请求调用此JSP。 I want to check if there are any other options. 我想检查是否还有其他选择。

I am using JDK1.6, JBoss 5.1. 我正在使用JDK1.6,JBoss 5.1。

SOAP web service requests are normal POST HTTP requests which you can trigger using any client, including simple URLConnection or even curl . SOAP Web服务请求是普通的POST HTTP请求,您可以使用任何客户端触发它,包括简单的URLConnection甚至curl See: Sending a SOAP request to a Web Service via URLConnection . 请参阅: 通过URLConnection将SOAP请求发送到Web服务

You don't need a JSP (in fact, calling external web services from JSP is a terrible idea from maintenance perspective). 您不需要JSP(实际上,从维护角度来看,从JSP调用外部Web服务是一个糟糕的主意)。 You can call web services from any Java code, even directly from main method. 您可以从任何Java代码调用Web服务,甚至可以直接从main方法调用。

Try this out... 试试这个......

public void postData() throws Exception {


 HttpClient client = new DefaultHttpClient();
 HttpPost httppost = new HttpPost("https://www.xyz.com");

 List<NameValuePair> list = new ArrayList<NameValuePair>(1);

 list.add(new BasicNameValuePair("name","ABC");

 httppost.setEntity(new UrlEncodedFormEntity(list));

 HttpResponse r = client.execute(httppost);

}

I agree with Tomasz Nurkiewicz. 我同意Tomasz Nurkiewicz的观点。 Do not use a JSP to call the web service. 不要使用JSP调用Web服务。

Instead, create a web service that calls the other web service you need. 而是,创建一个调用您需要的其他Web服务的Web服务。 This way you can easily work with the result before sending back the response. 这样,您可以在返回响应之前轻松处理结果。

Web services can be easily created on JBoss using annotations. 可以使用注释在JBoss上轻松创建Web服务。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM