[英]Android communication with asp.net web service
我正在尝试将数据发布到asp.net Web服务,但似乎我不知道该怎么做。 所以我需要像这样发布数据
之后,我得到这样的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
}
所以任何人都可以指导我如何将数据发布到此Web服务
试试这个,但是我不是asp.net专家:/
HttpClient httpclient = new DefaultHttpClient();
HttpPost httppost = new HttpPost("http://yoors.somee.com/Default.aspx?type=EmailInsert");
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);
java.util.Scanner s = new java.util.Scanner(response.getEntity().getContent()).useDelimiter("\\A");
responseString = s.hasNext() ? s.next() : "";
Log.d("Debug", responseString);
} catch (ClientProtocolException e) {
// TODO Auto-generated catch block
} catch (IOException e) {
// TODO Auto-generated catch block
}
更新:
HttpPost httppost = new HttpPost("http://yoors.somee.com/Default.aspx?type=EmailInsert&username=MYUSERNAME&password=MYPASS&name=MYNAME&email=MYEMAIL@PROVIDER.com&emailenabled=FALSE");
可以正常工作,但是还不是很漂亮...我想可以找到一些东西!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.