【发布时间】:2015-07-29 19:54:12
【问题描述】:
我尝试做一个简单的登录功能。 登录将由应用程序进行,信息将发送到 WebService(在 C# 中)。
我的应用程序通过 HttpPost 将信息发送到服务器。但我无法在 Web 服务端获取和返回此信息
为了提出我正在使用的请求(android 端):
// Building Parameters
List<NameValuePair> params = new ArrayList<NameValuePair>();
params.add(new BasicNameValuePair("username", user.getText().toString()));
params.add(new BasicNameValuePair("password", pass.getText().toString()));
DefaultHttpClient httpClient = new DefaultHttpClient();
HttpPost httpPost = new HttpPost(url);
httpPost.setEntity(new UrlEncodedFormEntity(params));
HttpResponse httpResponse = httpClient.execute(httpPost);
HttpEntity httpEntity = httpResponse.getEntity();
is = httpEntity.getContent();
在 WebService 方面,我尝试使用 Serialize 方法,但它不起作用
Ps.:为了测试,我尝试在另一个 WebService 上运行(这个是用 PHP 构建的),并且工作正常。
任何想法如何使这项工作?
[编辑]
这是网络服务端:
[HttpPost]
public string LogarAplicativo()
{
//Request.InputStream.Seek(0, SeekOrigin.Begin);
string jsonData = new StreamReader(Request.InputStream).ReadToEnd();
dynamic data = JObject.Parse(jsonData);
//DB validation's
var json = "";
var serializer = new JavaScriptSerializer();
json = serializer.Serialize(new { success = "0", message = "Test message!" });
return json;
}
【问题讨论】:
-
显示您的网络服务代码,并解释“不起作用”的含义。您是否尝试过从浏览器调用 Web 服务?
-
嘿@nasch,我用Web 服务端更新帖子。不起作用是指函数'LogarAplicativo'无法读取httppost(在应用程序端)传递的信息
-
我用fiddler在浏览器上测试,json响应正确
标签: c# android json web-services