我需要使用Android來使用SOAP Web服務。使用KSOAP進行Android的基本HTTP認證
問題是,在請求特定函數之前,我需要使用基本http請求來驗證客戶端。
你知道如何使用KSOAP來做到這一點嗎?
直到這一刻我使用httpsTransportSE.call的重載方法(),因爲它表明,我可以爲HTTP連接指定額外的頭已經嘗試
headerPropertyList.add(new HeaderProperty("Authorization", "Basic : dXNlcjpwYXNz"));
「cdXNlcjpwYXNz」是base 64編碼的「user:pass」字符串
public List call(String soapAction, SoapEnvelope envelope, List headers)
* @param headers a list of HeaderProperties to be http header properties when establishing the connection
private static final String SOAP_ACTION = "someaddress/IPortReporting/GetPortStatus";
private static final String METHOD_NAME = "methodname";
private static final String NAMESPACE = "http://ssn.someaddress/2.0/";
private static final String URL = "new.someaddress/functionName.svc";
SoapObject Request = new SoapObject(NAMESPACE, METHOD_NAME);
Request.addProperty("MessageId", "1");
SoapSerializationEnvelope soapEnvelop = new SoapSerializationEnvelope(
11);
//soapEnvelop.headerOut = addHeaders();
soapEnvelop.dotNet = true;
soapEnvelop.setOutputSoapObject(Request);
List<HeaderProperty> headerPropertieList = new ArrayList<HeaderProperty>();
headerPropertyList.add(new HeaderProperty("Authorization", "Basic : cG9ydHdzOjEyM3F3ZUFTRA=="));
//HeaderProperty headerProperty = new HeaderProperty()
HttpsTransportSE httpsse = new HttpsTransportSE(URL, 443, "", 5000);
try {
httpsse.call(SOAP_ACTION, soapEnvelop, headerPropertyList);
//httpsse.call(SOAP_ACTION, soapEnvelop);
SoapPrimitive resultString = (SoapPrimitive) soapEnvelop
.getResponse();
tv.setText("Status: ");
} catch (Exception e) {
tv.setText("Some error," + " "
+ e.getMessage());
}
但我有消息「權限被拒絕」報告回來。
當實例headerPropertyList你寫屬性,但後來,當你設置它,你怎麼稱呼它propertie可能? – GriffiN 2011-07-12 20:26:35