0
我已經搜索了一段時間的互聯網,我無法讓我的Android應用程序發送註冊ID和設備ID到服務器。我確定有一些簡單的東西我錯過了,但任何人都可以看到我做錯了什麼?代碼被擊中,Toasts被顯示出來,但服務器沒有做任何事情,但如果我直接去URL,它就是我想要的。一旦我得到它的工作,因爲它是沒有意義的,因爲我想要的東西如何發送C2DM註冊ID到服務器
if (!regId.equals("")) {
Toast.makeText(context, "The registration ID is: " + regId,
Toast.LENGTH_LONG).show();
Toast.makeText(context, "The device ID is: " + deviceId,
Toast.LENGTH_LONG).show();
// Create a new HttpClient and Post Header
HttpClient httpclient = new DefaultHttpClient();
HttpPost httppost = new HttpPost("http://uni.britintel.co.uk/register.php");
try {
// Add your data
List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(1);
nameValuePairs.add(new BasicNameValuePair("deviceId", deviceId));
nameValuePairs.add(new BasicNameValuePair("registrationId", regId));
httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
// Execute HTTP Post Request
HttpResponse httpresponse = httpclient.execute(httppost);
BufferedReader rd = new BufferedReader(new InputStreamReader(
httpresponse.getEntity().getContent()));
String line = "";
while ((line = rd.readLine()) != null) {
Log.e("HttpResponse", line);
Toast.makeText(context, line,
Toast.LENGTH_LONG).show();
}
} catch (ClientProtocolException e) {
// TODO Auto-generated catch block
} catch (IOException e) {
// TODO Auto-generated catch block
}
} else {
Toast.makeText(context, "The registration ID doesn't exist",
Toast.LENGTH_LONG).show();
}
緩衝的讀者將被刪除。
非常感謝您的幫助。
我試圖使用GET而不是POST,但它仍然不想工作 – gigaSproule 2012-01-17 15:08:01