与HttpPost的连接问题

时间:2014-05-17 14:13:03

标签: android mysql http-post

我第一次来到这里,我真的需要你的帮助,因为我被卡住了!

我正在编写一个Android应用程序来管理二手书店。

现在,我可以扫描条形码,向google.books询问有关我扫描内容的信息并显示这些信息。

现在,我尝试将这些数据注入Internet上的Mysql数据库。

我尝试使用httpPost,但没有成功。在我的httppost之后,我要求httpResponse,我收到404!

这是我的代码:

public class InsertionDb extends AsyncTask<String, Void, String> {

@Override
protected String doInBackground(String... params) {

    String isbn = (String) params[0];
    String auteur = (String) params[1].replaceAll("[\\W]", "");     ;
    String titre = (String) params[2].replaceAll("\\s+", "_");

    HttpClient httpclient = new DefaultHttpClient();
    HttpPost httppost = new HttpPost("http://xxx.net/www/xxxs/xxx.php");
    try {
        List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(3);
        nameValuePairs.add(new BasicNameValuePair("isbn", isbn));
        nameValuePairs.add(new BasicNameValuePair("auteur", auteur));
        nameValuePairs.add(new BasicNameValuePair("titre", titre));
        httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));

        // Execute HTTP Post Request
        HttpResponse response = httpclient.execute(httppost);
        StatusLine statutRecherche = response.getStatusLine();
        if (statutRecherche.getStatusCode() == 200) {
            Log.i("Works","Hoo Yeah !!" + statutRecherche.getStatusCode());

        } else {
            Log.e("error","WTF?" + statutRecherche.getStatusCode());
        }

    } catch (ClientProtocolException e) {
        Log.e("Protocole", "Error into protocol " + e.toString());
    } catch (IOException e) {
        Log.e("IOproblem", "error with IO " + e.toString());
    }

    catch (Exception e) {
        // TODO: handle exception
    }
    return null;
}
}

如果我在我的Android网络浏览器中尝试使用该网址,那就可以了。

互联网连接有效,因为我可以为我的google.books搜索创建一个httpGet。

有人可以帮助我吗?

0 个答案:

没有答案