从android eclipse消费Web服务
我是[android eclipse]的纯粹初学者,这里我需要从url使用web服务”http://122.248.240.105:93“通过安卓eclipse,所以 请列出使用web服务的步骤,如果可能,请从该url或其他示例将演示作为任何一个web服务发送给我从android eclipse消费Web服务,android,eclipse,web-services,Android,Eclipse,Web Services,我是[android eclipse]的纯粹初学者,这里我需要从url使用web服务”http://122.248.240.105:93“通过安卓eclipse,所以 请列出使用web服务的步骤,如果可能,请从该url或其他示例将演示作为任何一个web服务发送给我 非常感谢您可以非常轻松地使用restful服务。 对于数据交换,更喜欢json而不是XML。 我附上一个来自android客户端的restful服务调用示例,其中包含JSON public class LoginService {
非常感谢您可以非常轻松地使用restful服务。 对于数据交换,更喜欢json而不是XML。 我附上一个来自android客户端的restful服务调用示例,其中包含JSON
public class LoginService {
loginurl="http:/yourhostname.com/Service.svc/Service/ValidateMobileUser";
/**
* This method is used to validate client name from wcf
*
* @param 1: username
* @param 2: password *
* @return true or false as string value
*/
public String authenticate(String userName, String passWord
) throws JSONException, IllegalStateException,
IOException,NullPointerException {
Log.d("input authenticate method", userName + passWord );
HttpPost request = new HttpPost(loginurl);
request.setHeader("Accept", "application/json");
request.setHeader("Content-type", "application/json");
JSONObject json = new JSONObject();
json.put("UserName", userName);
json.put("Password", passWord);
json.toString();
JSONStringer str = new JSONStringer().object().key("clientEntity")
.value(json).endObject();
StringEntity entity = new StringEntity(str.toString());
request.setEntity(entity);
DefaultHttpClient httpClient = new DefaultHttpClient();
HttpResponse response = httpClient.execute(request);
Log.e("Status code ", "status code is " + response.getStatusLine());
HttpEntity responseEntity = response.getEntity();
char[] buffer = new char[(int) responseEntity.getContentLength()];
InputStream stream = responseEntity.getContent();
InputStreamReader reader = new InputStreamReader(stream);
reader.read(buffer);
stream.close();
String response_str = new String(buffer);
int i = response.getStatusLine().getStatusCode();
if (i == 200) {
Log.d("output authenticate method", response_str);
return response_str;
} else {
response_str = Integer.toString(i);
return response_str;
}
}
}
我在代码中使用了restful WCF和Json。
您可以将其用作带有json的restful服务的模板。
对于restful服务
我更喜欢带json的restful,但如果您想阅读ksoap教程,我建议您阅读:
网络服务:
saxparser:
kshop:
可抽取图片:
如果答案对你有帮助,请接受。谢谢您想使用哪种类型的服务?