0

这是我的代码:

// begin the registration process
    status.setText("Registering...");
    HttpClient httpclient = new DefaultHttpClient();
    HttpPost httppost = new HttpPost("register.php");
    SharedPreferences settings = getSharedPreferences("settings", 0);
    String name = settings.getString("name", "");
    String email = settings.getString("email", "");
    String password = settings.getString("password", "");

    //get C2DM registration ID
    Context context = getApplicationContext();
    C2DMessaging.register(context, "qasim1iqbal");
    String reg_id = C2DMessaging.getRegistrationId(context);

    String HTML = "";
    try {
        List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(2);
        nameValuePairs.add(new BasicNameValuePair("name", name));
        nameValuePairs.add(new BasicNameValuePair("email", email));
        nameValuePairs.add(new BasicNameValuePair("password", password));
        nameValuePairs.add(new BasicNameValuePair("reg_id", reg_id));
        httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));

        HttpResponse response = httpclient.execute(httppost);
        HTML = EntityUtils.toString(response.getEntity());
        Toast msg = Toast.makeText(getApplicationContext(), HTML, Toast.LENGTH_LONG);
        msg.show();

        Intent i = new Intent(getBaseContext(), doneRegisterActivity.class);
        startActivityForResult(i, 0);
    } catch (ClientProtocolException e) {
    } catch (IOException e) {
    }

我在注册时收到 SERVICE_NOT_AVAILABLE 错误,这可能是什么原因造成的?这是在一个活动上。

4

1 回答 1

2

C2DM 页面

设备无法读取响应,或者来自服务器的 500/503 可以稍后重试。应用程序应使用指数退避并重试。

可能是服务器打嗝。(即,怀疑这是你的事情)。可以肯定的是,请尝试将您的凭据与该页面上列出的示例应用程序之一一起使用,看看它是否在那里工作。

于 2011-08-09T00:48:08.903 回答