2013-02-19 150 views
0

我正在爲android項目使用kso​​ap2。但服務器代碼(無法更改)是舊的,需要在HTTP標頭的標頭內發送一些屬性。將標題添加到Http標題

服務器使用肥皂,所以我決定使用android的ksoap2,但我找不到任何示例如何設置ksoap2請求的HTTP標頭(不是在肥皂信封裏面,而是在httpheader裏面)。

可能嗎?

如果可能的話,任何人都可以給我看一個例子嗎?

回答

0

您可以檢索的連接對象,並添加標題那裏。

HttpTransportSE transport = new HttpTransportSE(url,timeout); 
ServiceConnection conn = transport.getConnection(); 
conn.setRequestProperty("Accept-Encoding", "utf-8"); 
//and others... 
0

HTTP標頭可以在org.ksoap2.transport.call(String,SoapEnvelope,List,File)方法中修改。

編輯

您可以調用HttpTransportSE.call()

例如,當直接傳遞額外的頭:

. 
. 
. 
List<HeaderProperty> headers; 
headers.add(new HeaderProperty("Content-Type", "utf8")); 
headers.add(new HeaderProperty("Accept", "text/html")); 

HttpTransportSE httpTransport = new HttpTransportSE(_soapAddress); 

httpTransport.call(soapAction, envelope, headers); 
. 
. 
. 
+0

歡迎來到StackOverflow,請提供更多信息,可能是您的答案的來源,因爲它表明這是一個非常差的答案。 – 2013-02-20 12:21:48

+0

該源碼是回答ksoap2的源代碼 - https://github.com/mosabua/ksoap2-android – 2013-02-22 18:32:24