1

在我的应用程序中,我使用 http 将用户信息发送到服务器,如下所示,我得到org.apache.http.client.HttpResponseException: Not Found并且我花了更多时间但无法解决。请帮我找出解决方案。

我在这一行得到错误:

jsonResponse = httpClient.execute(httpPost, resHandler);

public String addNewCardDetail(String loggedin_id, String fn, String ln,
        String cardholdername, String cardno,String cvv, String expdate, String add,
        String state, String city, String pincode) {

    jsonResponse = "";

    httpClient = new DefaultHttpClient();
    resHandler = new BasicResponseHandler();
    httpPost = new HttpPost("http://xxx.xxx.xxx.xx/users/createCustomerCardAddress");
    nameValuePairs = new ArrayList<NameValuePair>(11);

    nameValuePairs.add(new BasicNameValuePair("loggedin_id",loggedin_id));
    nameValuePairs.add(new BasicNameValuePair("firstname",fn));
    nameValuePairs.add(new BasicNameValuePair("lastname",ln));
    nameValuePairs.add(new BasicNameValuePair("cardHolderName",cardholdername));
    nameValuePairs.add(new BasicNameValuePair("cardNumber",cardno));
    nameValuePairs.add(new BasicNameValuePair("cardCvv",cvv));
    nameValuePairs.add(new BasicNameValuePair("expDate",expdate));
    nameValuePairs.add(new BasicNameValuePair("address",add));
    nameValuePairs.add(new BasicNameValuePair("state",state));
    nameValuePairs.add(new BasicNameValuePair("city",city));
    nameValuePairs.add(new BasicNameValuePair("pincode",pincode));

    Log.e("----------", "---------");
    for (int i = 0; i < nameValuePairs.size(); i++) {
        Log.e("add / edit new card", nameValuePairs.get(i).getName());
        Log.e("add / edit new card", nameValuePairs.get(i).getValue());
    }
    Log.e("----------", "---------");

    try {
        httpPost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
        jsonResponse = httpClient.execute(httpPost, resHandler); // I get org.apache.http.client.HttpResponseException: Not Found 
        Log.e("add edit card response", "-"+jsonResponse);
    } catch (UnsupportedEncodingException e) {
        e.printStackTrace();
    } catch (ClientProtocolException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    }
    return jsonResponse;
}

我的日志跟踪:

org.apache.http.client.HttpResponseException: Not Found
at org.apache.http.impl.client.BasicResponseHandler.handleResponse(BasicResponseHandler.java:71)
at org.apache.http.impl.client.BasicResponseHandler.handleResponse(BasicResponseHandler.java:59)
at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:773)
at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:743)
at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:732)
at com.fssd.spot.parser.ParsorClass.addNewCardDetail(ParsorClass.java:1098)
at com.fssd.spot.payment.BillingAddress$AddNewcard.doInBackground(BillingAddress.java:146)
at com.fssd.spot.payment.BillingAddress$AddNewcard.doInBackground(BillingAddress.java:1)
at android.os.AsyncTask$2.call(AsyncTask.java:287)
at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:305)
at java.util.concurrent.FutureTask.run(FutureTask.java:137)
at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:230)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1076)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:569)
at java.lang.Thread.run(Thread.java:856)
4

3 回答 3

3

给定的 Api 无效,所以我得到了这个异常。现在我得到了有效的 api 和工作。谢谢。

于 2013-12-10T09:20:54.833 回答
0

请检查服务器端编码...可能是您没有从服务器获得正确的响应。

于 2013-12-10T09:09:47.523 回答
0

此错误导致 URL 的授权无效。请重新检查 HTTP 请求,然后再做一次。

于 2020-02-19T06:01:31.233 回答