我已经开发了一个将数据发送到服务器的应用程序,但是当我尝试运行它时,我在执行 http 请求时遇到错误......
这是代码...
public void send()
{
// get the message from the message text box
String msg = msgTextField.getText().toString();
System.out.println("I am here!!!");
// make sure the fields are not empty
if (msg.length()>0)
{
Toast.makeText(this, "started", Toast.LENGTH_LONG).show();
DefaultHttpClient httpclient=new DefaultHttpClient();
HttpPost httppost = new HttpPost("http://www.fblocation.asia/update/index.php");
List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>();
nameValuePairs.add(new BasicNameValuePair("lat", Double.toString(clat)));
nameValuePairs.add(new BasicNameValuePair("long", Double.toString(clong)));
nameValuePairs.add(new BasicNameValuePair("username", msg));
try {
httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
httpclient.execute(httppost);
Toast.makeText(this, "sent", Toast.LENGTH_LONG).show();
} catch (Exception e) {
Toast t=Toast.makeText(getApplicationContext(),e.getMessage(), Toast.LENGTH_LONG);
t.show();
}
}
else
{
// display message if text fields are empty
Toast.makeText(getBaseContext(),"All field are required",Toast.LENGTH_SHORT).show();
}
}
请给我一些建议。
谢谢!