Android Java-使用Post请求调用WCF Rest Web服务
我已经厌倦了对一些看似简单但却不是给予的事情进行轮换,我已经浏览了所有的论坛和图图提亚 我想在android中通过POST请求调用WCF Rest Web服务 在c#中,我可以发送帖子、url和“body param” 但在android(java)中发送参数时,webservice方法(尽管我无法连接)dizme认为数据始终无效 到目前为止,我的代码是这样的,这是主要的连接方法:Android Java-使用Post请求调用WCF Rest Web服务,android,rest,post,request,webservices-client,Android,Rest,Post,Request,Webservices Client,我已经厌倦了对一些看似简单但却不是给予的事情进行轮换,我已经浏览了所有的论坛和图图提亚 我想在android中通过POST请求调用WCF Rest Web服务 在c#中,我可以发送帖子、url和“body param” 但在android(java)中发送参数时,webservice方法(尽管我无法连接)dizme认为数据始终无效 到目前为止,我的代码是这样的,这是主要的连接方法: public void LoginWS(final String urlWS, final String user
public void LoginWS(final String urlWS, final String user) throws Exception
{
Thread thread = new Thread(new Runnable() {
@Override
public void run()
{
try
{
//urlWS ="http://mywebsite/webservicename.svc/rest/methodnamePost";
String inputCoded = Base64.encodeToString(user.getBytes("UTF-8"), Base64.NO_WRAP);
HttpURLConnection request = (HttpURLConnection) new URL(urlWS).openConnection();
try {
request.setDoOutput(true);
request.setDoInput(true);
request.setRequestProperty("Content-Type", "application/json");
request.setRequestMethod("POST");
request.connect();
InputStream is = request.getInputStream();
String resp = convertStreamToString(is);
byte[] data = Base64.decode(resp, Base64.NO_WRAP);
response = new String(data, "UTF-8");
is.close();
} finally {
request.disconnect();
}
}
catch (Exception ex)
{
ex.printStackTrace();
}
}
});
thread.start();
}
在webservice端,方法签名如下:
[OperationContract]
[WebInvoke(Method = "POST", RequestFormat = WebMessageFormat.Json, ResponseFormat = WebMessageFormat.Json)]
string methodnamePost(string input);
如果有人能帮助我了解如何发送POST请求发送不带名称的参数
,那就太好了