を使用して作成されている長いURLがあり、現在、投稿によって一部のデバイスで500エラーが発生し、他のデバイスでは200エラーが発生nameValuePairs
する理由を解明しようとしています。私は完全なURLを抽出する必要がありますが、私が理解しているように、それは次の形式である必要があります。httppost
http://xx.com/site.asmx?var1=blah?var2=blah
また、同じビルドが携帯電話でも機能しますが、タブレットでは機能しません。私は自分のコードを調べて、タブレットがこのような変数を定義できない可能性がある場所を見つけようとしました。
final TelephonyManager tm = (TelephonyManager) getBaseContext()
.getSystemService(Context.TELEPHONY_SERVICE);
String tmDevice;
try{
tmDevice = "" + tm.getDeviceId().toString();
}
catch (NullPointerException e)
{
tmDevice = "null";
}
nameValuePairs
コードの投稿部分からの抜粋と外観の一部を次に示します。
List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(2);
nameValuePairs
.add(new BasicNameValuePair("CurrentOwnerUsername", name));
nameValuePairs.add(new BasicNameValuePair("OSVersion",
Build.VERSION.RELEASE));
nameValuePairs.add(new BasicNameValuePair("hash",
"xxx"));
nameValuePairs.add(new BasicNameValuePair("OSName", "Android"));
nameValuePairs.add(new BasicNameValuePair("Model", Build.MODEL));
nameValuePairs.add(new BasicNameValuePair("Manufacturer",
Build.MANUFACTURER));
nameValuePairs.add(new BasicNameValuePair("IMEI", id));
try {
nameValuePairs.add(new BasicNameValuePair("SerialNumber",
Build.SERIAL));
} catch (NoSuchFieldError e) {
nameValuePairs.add(new BasicNameValuePair("SerialNumber",
"NotAvailable"));
}
nameValuePairs.add(new BasicNameValuePair("CarrierName", carrier));
// .add(new BasicNameValuePair("FriendlyName", Build.DEVICE));
nameValuePairs.add(new BasicNameValuePair("Type", " "));
nameValuePairs.add(new BasicNameValuePair("VisitorID", VisitorID));
nameValuePairs.add(new BasicNameValuePair("PhoneNumber", phoneNumber));
nameValuePairs.add(new BasicNameValuePair("SSID", ssid));
nameValuePairs.add(new BasicNameValuePair("MACAddress", macAddr));
nameValuePairs.add(new BasicNameValuePair("UserDepartment",
department_val));
nameValuePairs.add(new BasicNameValuePair("BatteryLevel", batteryText));
int toastDuration = Toast.LENGTH_SHORT;
try {
HttpPost httppost = new HttpPost(URL); // post object
httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
HttpResponse response = httpclient.execute(httppost); // execution
int result = response.getStatusLine().getStatusCode();
if (result == 200) {
CharSequence toastText = "Success";
Toast.makeText(context, toastText, toastDuration).show();
} else {
CharSequence toastText = "Failure";
Log.d("checkin", String.valueOf(response.getStatusLine()
.getStatusCode()));
Toast.makeText(context, toastText, toastDuration).show();
}
} catch (ClientProtocolException e) {
CharSequence toastText = "ClientProtocolException";
Toast.makeText(context, toastText, toastDuration).show();
} catch (IOException e) {
CharSequence toastText = "IOException";
Toast.makeText(context, toastText, toastDuration).show();
}
したがって、必要なのは、完成したURLをからプルする方法httppost
です。渡される現在の文字列は、http: //xx.com/URL
などの単純なベースURLであり、それに続きます。考え?nameValuePairs