开发者

Using HttpGet to execute command in a Webserver

Hey All, I'm doing 开发者_运维知识库a project on remotely controlling my RC car with an installed adruino board and wifly shied. The wifly shied has its own webserver set up and the configurations of moving up, down, left and right is set. However, I have problems in my android app regarding how to access the webserver when I click my move forward button. Below is the sample code and I'm stuck from there.

public class GetUrl extends Activity implements OnClickListener {

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

        View forward_Button = findViewById(R.id.forwardButton);
        forward_Button.setOnClickListener(this);
}
@Override
    public void onClick(View v) {

        switch (v.getId()) {
        case R.id.forwardButton:
            HttpClient httpclient = new DefaultHttpClient();
            HttpGet httpget = new HttpGet("http://192.168.1.3/?LED=Fowd");
            HttpResponse response = httpclient.execute(httpget);

            break;


JAVA 101 : httpclient.execute(httpget); throws an exception that you have to catch :

try {
  httpclient.execute(httpget);
} catch (ClientProtocolException e) {
  e.printStackStrace();
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜