當前位置:首頁 » 密碼管理 » 瀏覽器訪問介面

瀏覽器訪問介面

發布時間: 2023-07-14 23:04:13

⑴ 使用瀏覽器怎麼調用java Web Service的介面

Java通過WSDL文件來調用webservice:

注意,以下的代碼並沒有經過真正的測試,只是說明這些情況,不同版本的Axis相差很大,大家最好以apache網站上的例子為准,這里僅僅用於說明其基本用法。
1,直接AXIS調用遠程的web service
這種方法比較適合那些高手,他們能直接看懂XML格式的WSDL文件,我自己是看不懂的,尤其我不是專門搞這行的,即使一段時間看懂,後來也就忘記了。直接調用模式如下:
import java.util.Date;
import java.text.DateFormat;
import org.apache.axis.client.Call;
import org.apache.axis.client.Service;
import javax.xml.namespace.QName;
import java.lang.Integer;
import javax.xml.rpc.ParameterMode;

public class caClient {

public static void main(String[] args) {

try {
String endpoint = "";
//直接引用遠程的wsdl文件
//以下都是套路
Service service = new Service();
Call call = (Call) service.createCall();
call.setTargetEndpointAddress(endpoint);
call.setOperationName("addUser");//WSDL裡面描述的介面名稱
call.addParameter("userName", org.apache.axis.encoding.XMLType.XSD_DATE,
javax.xml.rpc.ParameterMode.IN);//介面的參數
call.setReturnType(org.apache.axis.encoding.XMLType.XSD_STRING);//設置返回類型

String temp = "測試人員";
String result = (String)call.invoke(new Object[]{temp});
//給方法傳遞參數,並且調用方法
System.out.println("result is "+result);
}
catch (Exception e) {
System.err.println(e.toString());
}
}
}
2,直接SOAP調用遠程的webservice
這種模式我從來沒有見過,也沒有試過,但是網路上有人貼出來,我也轉過來
import org.apache.soap.util.xml.*;
import org.apache.soap.*;
import org.apache.soap.rpc.*;

import java.io.*;
import java.net.*;
import java.util.Vector;

public class caService{
public static String getService(String user) {
URL url = null;
try {
url=new URL("");
} catch (MalformedURLException mue) {
return mue.getMessage();
}
// This is the main SOAP object
Call soapCall = new Call();
// Use SOAP encoding
soapCall.setEncodingStyleURI(Constants.NS_URI_SOAP_ENC);
// This is the remote object we're asking for the price
soapCall.setTargetObjectURI("urn:xmethods-caSynrochnized");
// This is the name of the method on the above object
soapCall.setMethodName("getUser");
// We need to send the ISBN number as an input parameter to the method
Vector soapParams = new Vector();

// name, type, value, encoding style
Parameter isbnParam = new Parameter("userName", String.class, user, null);
soapParams.addElement(isbnParam);
soapCall.setParams(soapParams);
try {
// Invoke the remote method on the object
Response soapResponse = soapCall.invoke(url,"");
// Check to see if there is an error, return "N/A"
if (soapResponse.generatedFault()) {
Fault fault = soapResponse.getFault();
String f = fault.getFaultString();
return f;
} else {
// read result
Parameter soapResult = soapResponse.getReturnValue ();
// get a string from the result
return soapResult.getValue().toString();
}
} catch (SOAPException se) {
return se.getMessage();
}
}
}

⑵ 部署在遠程伺服器上的web項目怎樣在瀏覽器中訪問本地埠

1、按配置跳板機:首先得有一台能通過ssh登錄雲端伺服器的跳板機(堡壘機)。
2、建立一條ssh隧道。
3、訪問(必須登錄上上面配置好的跳板機,不必登錄雲端伺服器)。以上是部署在遠程伺服器上的web項目在瀏覽器中訪問本地埠的方法。

⑶ java 如何模擬瀏覽器調用rest api介面

用Apache的HttpClient包可以直接發請求

熱點內容
滑板鞋腳本視頻 發布:2025-02-02 09:48:54 瀏覽:432
群暉怎麼玩安卓模擬器 發布:2025-02-02 09:45:23 瀏覽:557
三星安卓12彩蛋怎麼玩 發布:2025-02-02 09:44:39 瀏覽:743
電腦顯示連接伺服器錯誤 發布:2025-02-02 09:24:10 瀏覽:537
瑞芯微開發板編譯 發布:2025-02-02 09:22:54 瀏覽:146
linux虛擬機用gcc編譯時顯示錯誤 發布:2025-02-02 09:14:01 瀏覽:235
java駝峰 發布:2025-02-02 09:13:26 瀏覽:651
魔獸腳本怎麼用 發布:2025-02-02 09:10:28 瀏覽:538
linuxadobe 發布:2025-02-02 09:09:43 瀏覽:212
sql2000資料庫連接 發布:2025-02-02 09:09:43 瀏覽:726