【发布时间】:2013-07-25 09:45:37
【问题描述】:
我正在尝试将数据发布到 asp.net 网络服务,但似乎我不知道该怎么做。所以我需要像这样发布数据
之后我得到这样的 JSON 响应
{"VALID":"success"}
目前我正在使用此功能,但似乎它不适用于此目的。 /
/ Create a new HttpClient and Post Header
HttpClient httpclient = new DefaultHttpClient();
HttpPost httppost = new HttpPost("http://yoors.somee.com/Default.aspx?type=EmailInsert");
// http://yoors.somee.com/Default.aspx?type=Email
// Insert&username=ben&password=pass&name=alv
//&email=ben@yahoo.com&emailenabled=false
try {
// Add your data
List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(2);
nameValuePairs.add(new BasicNameValuePair("username",userName));
nameValuePairs.add(new BasicNameValuePair("name", name));
nameValuePairs.add(new BasicNameValuePair("password", password));
nameValuePairs.add(new BasicNameValuePair("email", email));
httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
// Execute HTTP Post Request
HttpResponse response = httpclient.execute(httppost);
Toast.makeText(Signup.this, response.getAllHeaders().toString(), Toast.LENGTH_LONG).show();
} catch (ClientProtocolException e) {
// TODO Auto-generated catch block
} catch (IOException e) {
// TODO Auto-generated catch block
}
任何人都可以指导我如何将数据发布到此网络服务
【问题讨论】:
-
您确定要发帖吗?看起来你可以做一个 get (即将 url 复制到浏览器中)。在这种情况下,您可以使用类似:
new WebRequest(string.Format("http://yoors.somee.com/Default.aspx?type=EmailInsert&username={0}&password={1}&name={2}&email={3}&emailenabled=false", userName, password, name, email) ).GetResponse(); -
如果将
response.getAllHeaders().toString()替换为response.getStatusLine().getStatusCode()会得到什么 -
@Skaard-Solo 我得到 200
-
因此,您可以致电 WS。我认为更多的是关于参数。你能在执行之前获取httppost URL吗?您收到 FAIL 还是其他信息?
-
@Skaard-Solo 你能举个例子吗?
标签: android asp.net web-services rest