我需要将以下数据发送到URl的webservice:
要发送的数据格式为:
new_member=[{"email":"himanshu@avigma.com","username":"himanshu01","pwd":"himanshu01"}]
其中email
、username
和pwd
是关键字,通过编辑文本字符串获取相应的值字符串。我在点击按钮时发布此数据。
我没有得到任何响应,因为我已经尝试与我的合作者进行反向检查,在他的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");
}
}
}
);
请帮助我,我是一个在Android中JSON解析的新手。谢谢。