Android HTTP发布到没有参数的URL

时间:2013-04-03 06:08:51

标签: android performance http

对Android很新,并尝试通过android对URL进行发布。我的网址看起来像这样。

                 http://192.168.101.111:7000/MyService.svc/home/updatejob/4600/XCV13030001/TTTT0000/CCCC0000/SSSS0000

我可以通过Advance rest客户端对此网址发帖,这样可以正常工作。这是我的android代码实现

public boolean updateInfo() {
    boolean result = false;
    HttpClient httpClient = new DefaultHttpClient();

    HttpPost httpPost = new HttpPost(url);
    List<NameValuePair> params = new ArrayList<NameValuePair>();
    params.add(new BasicNameValuePair("sbDriverID", sbDriverID.toString()));
    params.add(new BasicNameValuePair("sbJobNumber", sbJobNumber.toString()));
    params.add(new BasicNameValuePair("sbTrailerNumber", sbTrailerNumber.toString()));
    params.add(new BasicNameValuePair("sbContainerNumber", sbContainerNumber.toString()));
    params.add(new BasicNameValuePair("sbSealNumber", sbSealNumber.toString()));
    try {
        UrlEncodedFormEntity entity = new UrlEncodedFormEntity(params, "UTF-8");
        httpPost.setEntity(entity);
        HttpResponse httpResponse = httpClient.execute(httpPost);
        if (httpResponse != null) {
            if (httpResponse.getStatusLine().getStatusCode() == 204)
                result = true;
        }
    } catch (ClientProtocolException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    return result;
}

这给了我一个404.我努力了,找不到理由。

1 个答案:

答案 0 :(得分:0)

您是否尝试从无法连接的相同Android设备打开网址(使用浏览器)?也许Android设备位于不同的域中。