我正在尝试将一些数据发布到我的服务器(字符串)。我得到一个缺少的参数错误,但我不知道为什么。我注销了NameValuePair的内容,数据似乎就在那里。
我正在通过模拟器运行它。如果params在那里,有什么想法服务器会重新出现这样的错误吗?
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();
}
}
答案 0 :(得分:1)
你得到了
E/WebService(500): responseBody = Missing parameter: UserID.
当你尝试
时 Log.e(TAG, "responseBody = " + responseBody);
DocObjModParser dp = new DocObjModParser(context);
serviceStatus = dp.getPostTransactionResponseCode(responseBody); // <== this fails!
毫不奇怪,DocObjModParser无法解析响应字符串“Missing parameter:UserID。”
响应建议将用户ID添加到http查询。
我建议打印httppost并尝试首先通过浏览器执行它(它可能会立即给你一个提示),然后,通过curl
,可以使用命令行实用程序在Linux或Cygwin中(不确定普通的Windows)。
另一个建议是将打印的httppost与有效的请求进行比较。谁知道,脚本可能对参数的顺序很敏感,或者某些字符串包含应该进行URL编码的字符。
UPD:问题可能在于标题
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>
答案 1 :(得分:1)