这是我第一次连接服务器。我试图将android应用程序中的值存储到我的服务器中运行的MySQL中。但是,我在连接到我的服务器时遇到问题。它显示“目标服务器无法响应”可能是什么问题?和解决方案?
.java class
public void sendRegistrationIdToServer(String deviceId,
String registrationId) {
Log.d("C2DM", "Sending registration ID to my application server");
HttpClient client = new DefaultHttpClient();
HttpPost post = new HttpPost("http://10.28.68.28/test.php?");
try {
List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(1);
// Get the deviceID
nameValuePairs.add(new BasicNameValuePair("deviceid", deviceId));
nameValuePairs.add(new BasicNameValuePair("registrationid",
registrationId));
//HttpProtocolParams.setUseExpectContinue(client.getParams(), false);
post.addHeader("Content-Type", "application/x-www-form-urlencoded");
post.setEntity(new UrlEncodedFormEntity(nameValuePairs,HTTP.UTF_8));
// Execute HTTP Post Request
HttpResponse response = client.execute(post);
int status = response.getStatusLine().getStatusCode();
System.out.println("HTTP Status = "+status);
BufferedReader rd = new BufferedReader(new InputStreamReader(
response.getEntity().getContent()));
String line = "";
while ((line = rd.readLine()) != null) {
Log.e("HttpResponse", line);
}
} catch (IOException e) {
e.printStackTrace();
}
}
错误讯息:
12-30 11:35:43.494: WARN/System.err(771): org.apache.http.NoHttpResponseException: The target server failed to respond
12-30 11:35:43.504: WARN/System.err(771): at org.apache.http.impl.conn.DefaultResponseParser.parseHead(DefaultResponseParser.java:85)
12-30 11:35:43.504: WARN/System.err(771): at org.apache.http.impl.io.AbstractMessageParser.parse(AbstractMessageParser.java:174)
12-30 11:35:43.514: WARN/System.err(771): at org.apache.http.impl.AbstractHttpClientConnection.receiveResponseHeader(AbstractHttpClientConnection.java:179)
12-30 11:35:43.514: WARN/System.err(771): at org.apache.http.impl.conn.DefaultClientConnection.receiveResponseHeader(DefaultClientConnection.java:235)
12-30 11:35:43.514: WARN/System.err(771): at org.apache.http.impl.conn.AbstractClientConnAdapter.receiveResponseHeader(AbstractClientConnAdapter.java:259)
12-30 11:35:43.514: WARN/System.err(771): at org.apache.http.protocol.HttpRequestExecutor.doReceiveResponse(HttpRequestExecutor.java:279)
12-30 11:35:43.514: WARN/System.err(771): at org.apache.http.protocol.HttpRequestExecutor.execute(HttpRequestExecutor.java:121)
12-30 11:35:43.524: WARN/System.err(771): at org.apache.http.impl.client.DefaultRequestDirector.execute(DefaultRequestDirector.java:410)
12-30 11:35:43.524: WARN/System.err(771): at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:555)
12-30 11:35:43.524: WARN/System.err(771): at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:487)
12-30 11:35:43.524: WARN/System.err(771): at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:465)
12-30 11:35:43.524: WARN/System.err(771): at de.vogella.android.c2dm.simpleclient.C2DMReceiverReceiver.sendRegistrationIdToServer(C2DMReceiverReceiver.java:121)
12-30 11:35:43.535: WARN/System.err(771): at de.vogella.android.c2dm.simpleclient.C2DMReceiverReceiver.onReceive(C2DMReceiverReceiver.java:56)
12-30 11:35:43.535: WARN/System.err(771): at android.app.ActivityThread.handleReceiver(ActivityThread.java:1769)
12-30 11:35:43.535: WARN/System.err(771): at android.app.ActivityThread.access$2400(ActivityThread.java:117)
12-30 11:35:43.544: WARN/System.err(771): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:978)
12-30 11:35:43.553: WARN/System.err(771): at android.os.Handler.dispatchMessage(Handler.java:99)
答案 0 :(得分:0)
没有得到服务器的任何回复。首先,您是否从服务器返回任何值或响应?你有服务器在运行吗?如果没有,您可能想看一下XAMPP。它包含您的所有需求。