【发布时间】:2013-04-29 11:58:53
【问题描述】:
代码不工作。请帮忙。除数量外,该项目被添加到数据库中。它始终为零。这是为什么呢?
String value;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.creamy);
EditText et = (EditText) findViewById(R.id.CreamyEdit);
value = et.getText().toString();
Button b = (Button) findViewById(R.id.buttonCreamy);
b.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
Toast.makeText(Creamy.this, "Item Submitted", Toast.LENGTH_LONG).show();
HttpClient client = new DefaultHttpClient();
HttpPost post = new HttpPost(
"http://10.0.2.2:8080/http/test.php");
List<NameValuePair> pairs = new ArrayList<NameValuePair>();
pairs.add(new BasicNameValuePair("item", "Creamy Delight")); //reflected in db
pairs.add(new BasicNameValuePair("quantity", value)); //not reflected in db
try {
post.setEntity(new UrlEncodedFormEntity(pairs));
} catch (UnsupportedEncodingException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
try {
HttpResponse response = client.execute(post);
} catch (ClientProtocolException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e2) {
// TODO Auto-generated catch block
e2.printStackTrace();
}
}
});
请帮忙!
【问题讨论】:
-
我使用姜饼 (2.3.3)
-
向我们展示处理请求的服务器端代码。
-
@TomeTasche
-
Paul,请将代码添加到您的原始问题中。我在这里无法正确阅读。
标签: android http post http-post httpclient