Frage

I'm trying to post some data to my server(Strings). I'm getting a missing parameter error but i'm not sure why. I log out the contents of the NameValuePair and the data seems to be there.

I'm running this through the emulator. Are there any ideas why the server would reurn such an error if the params are there?

public String updateCall( String userID, String callID, String startTime, String duration, String carerID) {

        Log.e(TAG,"inside WS updateCall");

        DateTime now = new DateTime();
        DateTimeFormatter df = DateTimeFormat.forPattern("yyyy-MM-dd H:mm:ss.SSS");
        String formattedNowTime = df.print(now);


        List<NameValuePair> nameValuePairs = null;
        String serviceStatus = null;
        // Create a new HttpClient and Post Header
        HttpClient httpclient = new DefaultHttpClient();
        HttpPost httppost = new HttpPost("http://rr3test.carefree-app.co.uk/roadrunner.asmx/UpdateCall");


        userID = userID.trim();
        formattedNowTime = formattedNowTime.trim();
        callID = callID.trim();
        startTime = startTime.trim();
        duration = duration.trim();
        carerID = carerID.trim();



        try {
            // Add your data
            nameValuePairs = new ArrayList<NameValuePair>(2);
            nameValuePairs.add(new BasicNameValuePair("UserID", userID));
            nameValuePairs.add(new BasicNameValuePair("DateTime", formattedNowTime));
            nameValuePairs.add(new BasicNameValuePair("CallID", callID));
            nameValuePairs.add(new BasicNameValuePair("Start", startTime));
            nameValuePairs.add(new BasicNameValuePair("Duration", duration));
            nameValuePairs.add(new BasicNameValuePair("NewCarerID", carerID));

            Log.e(TAG, "userID = " + userID + " DateTime = " + formattedNowTime + " callID = " + callID + " startTime = " + startTime 
                                                                        + " duration = " + duration + " carerID = " + carerID);

            Log.e(TAG, "nameValuePair length = " + nameValuePairs.size());

            for(int i = 0; i < nameValuePairs.size(); i++){

                Log.e(TAG, "nameValuePairs" + nameValuePairs.get(i));

            }



            httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));


            Log.e(TAG, "httppost.getEntity() = " + httppost.getEntity().getContentLength());

            // Execute HTTP Post Request
            Log.e(TAG, "about to execute http post updateCall");
            HttpResponse response = httpclient.execute(httppost);


            Log.e(TAG, "just executed http post updateCall");
            String responseBody = EntityUtils.toString(response.getEntity());
            Log.e(TAG, "responseBody = " + responseBody);

            DocObjModParser dp = new DocObjModParser(context);
            serviceStatus = dp.getPostTransactionResponseCode(responseBody);

            Log.e(TAG, "serviceStatus = " + serviceStatus);




        } catch (ClientProtocolException e) {
            // TODO Auto-generated catch block
        } catch (IOException e) {
            // TODO Auto-generated catch block
        }finally{

            nameValuePairs.clear();
            nameValuePairs = null;

        }
        return serviceStatus;




    }//end of postData

.

02-17 17:14:15.268: E/WebService(500): inside WS updateCall
02-17 17:14:15.418: E/WebService(500): userID = 1 DateTime = 2014-02-17 17:14:15.307 callID = 464da2e9-4d48-4b7c-a134-3180ce0ef250 startTime = 17-Feb-2014 5:14 duration = 30 carerID = 761
02-17 17:14:15.458: E/WebService(500): nameValuePair length = 6
02-17 17:14:15.458: E/WebService(500): nameValuePairsUserID=1
02-17 17:14:15.458: E/WebService(500): nameValuePairsDateTime=2014-02-17 17:14:15.307
02-17 17:14:15.458: E/WebService(500): nameValuePairsCallID=464da2e9-4d48-4b7c-a134-3180ce0ef250
02-17 17:14:15.458: E/WebService(500): nameValuePairsStart=17-Feb-2014 5:14
02-17 17:14:15.458: E/WebService(500): nameValuePairsDuration=30
02-17 17:14:15.458: E/WebService(500): nameValuePairsNewCarerID=761
02-17 17:14:15.538: E/WebService(500): httppost.getEntity() = 141
02-17 17:14:15.538: E/WebService(500): about to execute http post updateCall
02-17 17:14:15.728: D/dalvikvm(500): GC_FOR_ALLOC freed 487K, 16% free 8965K/10631K, paused 98ms
02-17 17:14:15.728: I/dalvikvm-heap(500): Grow heap (frag case) to 8.926MB for 87396-byte allocation
02-17 17:14:15.828: D/dalvikvm(500): GC_FOR_ALLOC freed 0K, 16% free 9050K/10759K, paused 96ms
02-17 17:14:15.938: D/dalvikvm(500): GC_FOR_ALLOC freed 0K, 16% free 9050K/10759K, paused 97ms
02-17 17:14:15.938: I/dalvikvm-heap(500): Grow heap (frag case) to 9.009MB for 87396-byte allocation
02-17 17:14:16.048: D/dalvikvm(500): GC_FOR_ALLOC freed 0K, 17% free 9135K/10887K, paused 101ms
02-17 17:14:16.728: D/dalvikvm(500): GC_FOR_ALLOC freed 177K, 16% free 9237K/10887K, paused 95ms
02-17 17:14:16.741: I/dalvikvm-heap(500): Grow heap (frag case) to 9.192MB for 87396-byte allocation
02-17 17:14:16.838: D/dalvikvm(500): GC_FOR_ALLOC freed 0K, 16% free 9322K/11015K, paused 99ms
02-17 17:14:16.928: E/WebService(500): just executed http post updateCall
02-17 17:14:16.958: E/WebService(500): responseBody = Missing parameter: UserID.
02-17 17:14:16.958: E/DocObjModParser(500): inside domparser constructor
02-17 17:14:16.958: E/DocObjModParser(500): built the dom factory
02-17 17:14:16.968: W/dalvikvm(500): threadid=12: thread exiting with uncaught exception (group=0x40014760)
02-17 17:14:16.968: E/AndroidRuntime(500): FATAL EXCEPTION: AsyncTask #4
02-17 17:14:16.968: E/AndroidRuntime(500): java.lang.RuntimeException: An error occured while executing doInBackground()
02-17 17:14:16.968: E/AndroidRuntime(500):  at android.os.AsyncTask$3.done(AsyncTask.java:266)
02-17 17:14:16.968: E/AndroidRuntime(500):  at java.util.concurrent.FutureTask$Sync.innerSetException(FutureTask.java:273)
02-17 17:14:16.968: E/AndroidRuntime(500):  at java.util.concurrent.FutureTask.setException(FutureTask.java:124)
02-17 17:14:16.968: E/AndroidRuntime(500):  at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:307)
02-17 17:14:16.968: E/AndroidRuntime(500):  at java.util.concurrent.FutureTask.run(FutureTask.java:137)
02-17 17:14:16.968: E/AndroidRuntime(500):  at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1081)
02-17 17:14:16.968: E/AndroidRuntime(500):  at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:574)
02-17 17:14:16.968: E/AndroidRuntime(500):  at java.lang.Thread.run(Thread.java:1020)
02-17 17:14:16.968: E/AndroidRuntime(500): Caused by: java.lang.NullPointerException
02-17 17:14:16.968: E/AndroidRuntime(500):  at com.carefreegroup.rr3.carefreeoncall.DocObjModParser.getPostTransactionResponseCode(DocObjModParser.java:505)
02-17 17:14:16.968: E/AndroidRuntime(500):  at com.carefreegroup.rr3.carefreeoncall.WebService.updateCall(WebService.java:352)
02-17 17:14:16.968: E/AndroidRuntime(500):  at com.carefreegroup.rr3.carefreeoncall.UpdateCallDateTimeAndCarerActivity$AsyncUpDateCall.doInBackground(UpdateCallDateTimeAndCarerActivity.java:205)
02-17 17:14:16.968: E/AndroidRuntime(500):  at com.carefreegroup.rr3.carefreeoncall.UpdateCallDateTimeAndCarerActivity$AsyncUpDateCall.doInBackground(UpdateCallDateTimeAndCarerActivity.java:1)
02-17 17:14:16.968: E/AndroidRuntime(500):  at android.os.AsyncTask$2.call(AsyncTask.java:252)
02-17 17:14:16.968: E/AndroidRuntime(500):  at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:305)
02-17 17:14:16.968: E/AndroidRuntime(500):  ... 4 more
02-17 17:14:19.288: E/WindowManager(500): Activity com.carefreegroup.rr3.carefreeoncall.UpdateCallDateTimeAndCarerActivity has leaked window com.android.internal.policy.impl.PhoneWindow$DecorView@4079a3e8 that was originally added here
02-17 17:14:19.288: E/WindowManager(500): android.view.WindowLeaked: Activity com.carefreegroup.rr3.carefreeoncall.UpdateCallDateTimeAndCarerActivity has leaked window com.android.internal.policy.impl.PhoneWindow$DecorView@4079a3e8 that was originally added here
02-17 17:14:19.288: E/WindowManager(500):   at android.view.ViewRoot.<init>(ViewRoot.java:276)
02-17 17:14:19.288: E/WindowManager(500):   at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:152)
02-17 17:14:19.288: E/WindowManager(500):   at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:95)
02-17 17:14:19.288: E/WindowManager(500):   at android.view.Window$LocalWindowManager.addView(Window.java:514)
02-17 17:14:19.288: E/WindowManager(500):   at android.app.Dialog.show(Dialog.java:269)
02-17 17:14:19.288: E/WindowManager(500):   at com.carefreegroup.rr3.carefreeoncall.UpdateCallDateTimeAndCarerActivity$AsyncUpDateCall.onPreExecute(UpdateCallDateTimeAndCarerActivity.java:198)
02-17 17:14:19.288: E/WindowManager(500):   at android.os.AsyncTask.executeOnExecutor(AsyncTask.java:549)
02-17 17:14:19.288: E/WindowManager(500):   at android.os.AsyncTask.execute(AsyncTask.java:499)
02-17 17:14:19.288: E/WindowManager(500):   at com.carefreegroup.rr3.carefreeoncall.UpdateCallDateTimeAndCarerActivity$1.onClick(UpdateCallDateTimeAndCarerActivity.java:117)
02-17 17:14:19.288: E/WindowManager(500):   at com.android.internal.app.AlertController$ButtonHandler.handleMessage(AlertController.java:166)
02-17 17:14:19.288: E/WindowManager(500):   at android.os.Handler.dispatchMessage(Handler.java:99)
02-17 17:14:19.288: E/WindowManager(500):   at android.os.Looper.loop(Looper.java:126)
02-17 17:14:19.288: E/WindowManager(500):   at android.app.ActivityThread.main(ActivityThread.java:3997)
02-17 17:14:19.288: E/WindowManager(500):   at java.lang.reflect.Method.invokeNative(Native Method)
02-17 17:14:19.288: E/WindowManager(500):   at java.lang.reflect.Method.invoke(Method.java:491)
02-17 17:14:19.288: E/WindowManager(500):   at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:841)
02-17 17:14:19.288: E/WindowManager(500):   at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:599)
02-17 17:14:19.288: E/WindowManager(500):   at dalvik.system.NativeStart.main(Native Method)

.

private class AsyncUpDateCall extends AsyncTask<Void, Void, Void> {

        ProgressDialog progressDialog;

        @Override
        protected void onPreExecute() {



            progressDialog = new ProgressDialog(UpdateCallDateTimeAndCarerActivity.this);
            progressDialog.setTitle("Connecting to Server");
            progressDialog.setMessage("updating call...");
            progressDialog.setIndeterminate(true);
            progressDialog.show();

        };

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

            rrOnCallApp.webService.updateCall("1", callID, startTime, duration,
                    theCarerID);
            return null;
        }

        @Override
        protected void onPostExecute(Void result) {
            super.onPostExecute(result);

            if (progressDialog != null)
                progressDialog.dismiss();
        }

    }
War es hilfreich?

Lösung

You get

E/WebService(500): responseBody = Missing parameter: UserID.

while you try

        Log.e(TAG, "responseBody = " + responseBody);

        DocObjModParser dp = new DocObjModParser(context);
        serviceStatus = dp.getPostTransactionResponseCode(responseBody); // <== this fails!

No surprise, DocObjModParser cannot parse the response string "Missing parameter: UserID."

The response suggests adding the user id to the http query.

I'd suggest printing the httppost and trying to perform it via, at first, a browser (it may give you a hint immediately), and, at second, via curl, a command-line utility available in Linux or Cygwin (not sure about plain Windows).

Another suggestion is to compare the printed httppost with a request that works. Who knows, maybe the script is sensitive to the order of parameters or some string contains characters that should be URL-encoded.

UPD: the problem may be with the headers

curl -I https://rr3test.carefree-app.co.uk/roadrunner.asmx/UpdateCallTest
HTTP/1.0 200 Connection established

HTTP/1.1 500 Internal Server Error
Connection: Keep-Alive
Content-Length: 3026
Date: Tue, 18 Feb 2014 11:54:29 GMT
Content-Type: text/html; charset=utf-8
Server: Microsoft-IIS/7.5
Cache-Control: private
X-AspNet-Version: 2.0.50727
X-Powered-By: ASP.NET

UPD2:

$ curl -I -X GET -H "Accept: text/javascript, text/html, application/xml, */*" https://rr3test.carefree-app.co.uk/roadrunner.asmx/UpdateCallTest?UserID=asd
HTTP/1.0 200 Connection established

HTTP/1.1 200 OK
Connection: Keep-Alive
Content-Length: 95
Date: Tue, 18 Feb 2014 12:00:22 GMT
Content-Type: text/xml; charset=utf-8
Server: Microsoft-IIS/7.5
Cache-Control: private, max-age=0
X-AspNet-Version: 2.0.50727
X-Powered-By: ASP.NET


$ curl   --data "UserID=asd" -H "Accept: text/javascript, text/html, application/xml, */*" https://rr3test.carefree-app.co.uk/roadrunner.asmx/UpdateCallTest
<?xml version="1.0" encoding="utf-8"?>
<string xmlns="http://tempuri.org/">UserID=asd</string>

Andere Tipps

In seems that the client successfully sent the request to server, but the server response that parameter UserID not found. Please check the server code, one reason may be the server handle parameter with the GET method instead of POST (what you are using to send data now)

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top