【发布时间】:2012-06-05 20:41:00
【问题描述】:
我必须将以下数据发送到 URl 的 web 服务
要发送的数据格式为:
new_member=[{"email":"himanshu@avigma.com","username":"himanshu01","pwd":"himanshu01"}]
其中email,username和pwd是key,通过edittext字符串获取对应的value字符串。我在单击按钮时发布此数据。
我没有得到任何回复,因为我试图与我的合作开发人员在他的 iphone 相同的应用程序 iphone 版本中进行反核,因为服务器说用户名和密码无效。
我的Signup.java 班级是:
Button b1=(Button)findViewById(R.id.button1);
b1.setOnClickListener(new OnClickListener()
{
EditText e=(EditText)findViewById(R.id.editText1);
String a=e.getText().toString();
EditText e1=(EditText)findViewById(R.id.editText1);
String b=e1.getText().toString();
EditText e2=(EditText)findViewById(R.id.editText1);
String c=e2.getText().toString();
public void onClick(View v) {
// TODO Auto-generated method stub
HttpClient client = new DefaultHttpClient();
HttpConnectionParams.setConnectionTimeout(client.getParams(), 10000); //Timeout Limit
HttpResponse response;
JSONObject json = new JSONObject();
try{
HttpPost post = new HttpPost("URL");
//System.out.println(post);
json.put("email", a);
json.put("username", b);
json.put("pwd",c);
StringEntity se = new StringEntity( "JSON: " + json.toString());
se.setContentEncoding(new BasicHeader(HTTP.CONTENT_TYPE, "application/json"));
post.setEntity(se);
response = client.execute(post);
/*Checking response */
if(response!=null){
InputStream in = response.getEntity().getContent(); //Get the data in the entity
//System.out.println(response);
}
}
catch(Exception e){
e.printStackTrace();
System.out.println(e.toString());
//createDialog("Error", "Cannot Estabilish Connection");
}
}
}
);
请帮助我,我是 JSON 和 Android.Thanx 解析的新手。
【问题讨论】: