Android 不使用WCF的JSON REST
有没有任何方法可以使用REST发送JSON,而不用使用.NET中的WCF?其目的是将一个字符串从android移动客户端发送到.NET服务器,附加一个字符串并将其发送回android客户端。搜索结果只给我提供了SOAP,不推荐用于效率问题。看看。做JSON胜过休息 (Android)客户端:Android 不使用WCF的JSON REST,android,wcf,Android,Wcf,有没有任何方法可以使用REST发送JSON,而不用使用.NET中的WCF?其目的是将一个字符串从android移动客户端发送到.NET服务器,附加一个字符串并将其发送回android客户端。搜索结果只给我提供了SOAP,不推荐用于效率问题。看看。做JSON胜过休息 (Android)客户端: public String SendToWebFunc(List<NameValuePair> postParameters, String URL) { HttpClient client1
public String SendToWebFunc(List<NameValuePair> postParameters, String URL)
{
HttpClient client1 = new DefaultHttpClient();
HttpPost request = new HttpPost(URL);
String page="";
try
{
request.setEntity(new UrlEncodedFormEntity(postParameters));
UrlEncodedFormEntity formEntity = new UrlEncodedFormEntity(postParameters);
request.setEntity(formEntity);
HttpResponse response;
response = client1.execute(request); //Sends the actual request
//Decode response to string
BufferedReader in = new BufferedReader(new InputStreamReader(response.getEntity().getContent()));
String line1;
line1 = in.readLine();
while(line1!=null)
{
page=page+line1;
line1=in.readLine();
}
}
catch (ClientProtocolException e)
{
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
return page;
}
服务器上的ashx服务:
public class Register : IHttpHandler
{
public void ProcessRequest (HttpContext context)
{
String data = context.Request.Params["request_data"];
.
.
.
context.Response.Write("false");
}
}
您可以使用.asmx服务,但现在wcf更受欢迎。WCF还支持Restful JSON请求。请您指向一个链接。asmx是否支持Restful JSON?如果是,我如何从我的android客户端调用该服务?如果我需要向客户端发送一些东西怎么办?
public class Register : IHttpHandler
{
public void ProcessRequest (HttpContext context)
{
String data = context.Request.Params["request_data"];
.
.
.
context.Response.Write("false");
}
}