You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository has been archived by the owner on Apr 27, 2021. It is now read-only.
I try to Send POST request chatserver using android app, but chatserver didn't accept
I thought that chat server get request and it response 200
this is chatserver.js code which I changed
-------------------------------chatserver.js--------------------------------------------
var httpsServer = https.createServer(httpsOptions, function(request, response) {
var file = http_files[request.url];
if (file) {
response.writeHeader(200,{"content-type" : file.contentType});
response.write(file.content);
return response.end();
} else{
log("Received secure request for " + request.url);
response.writeHead(404);
response.end();
}
});
// Spin up the HTTPS server on the port assigned to this sample.
// This will be turned into a WebSocket port very shortly.
httpsServer.listen(6503, function() {
log("Server is listening on port 6503");
});
// Create the WebSocket server by converting the HTTPS server into one.
var wsServer = new WebSocketServer({
httpServer: httpsServer,
autoAcceptConnections: false
});
// Set up a "connect" message handler on our WebSocket server. This is
// called whenever a user connects to the server's port using the
// WebSocket protocol.
wsServer.on('request', function(request) {
if (!originIsAllowed(request.origin)) {
request.reject();
log("Connection from " + request.origin + " rejected.");
return;
}
// Accept the request and get a connection.
var connection = request.accept("json", request.origin);
// Add the new connection to our list of connections.
log("Connection accepted from " + connection.remoteAddress + ".");
connectionArray.push(connection);
I try to Send POST request chatserver using android app, but chatserver didn't accept
I thought that chat server get request and it response 200
this is chatserver.js code which I changed
-------------------------------chatserver.js--------------------------------------------
var httpsServer = https.createServer(httpsOptions, function(request, response) {
var file = http_files[request.url];
if (file) {
response.writeHeader(200,{"content-type" : file.contentType});
response.write(file.content);
return response.end();
} else{
log("Received secure request for " + request.url);
response.writeHead(404);
response.end();
}
});
// Spin up the HTTPS server on the port assigned to this sample.
// This will be turned into a WebSocket port very shortly.
httpsServer.listen(6503, function() {
log("Server is listening on port 6503");
});
// Create the WebSocket server by converting the HTTPS server into one.
var wsServer = new WebSocketServer({
httpServer: httpsServer,
autoAcceptConnections: false
});
// Set up a "connect" message handler on our WebSocket server. This is
// called whenever a user connects to the server's port using the
// WebSocket protocol.
wsServer.on('request', function(request) {
if (!originIsAllowed(request.origin)) {
request.reject();
log("Connection from " + request.origin + " rejected.");
return;
}
// Accept the request and get a connection.
var connection = request.accept("json", request.origin);
// Add the new connection to our list of connections.
log("Connection accepted from " + connection.remoteAddress + ".");
connectionArray.push(connection);
connection.clientID = nextID;
nextID++;
--------------------------------chatserver.js-------------------------------------------
and this is android app code which responseCode are always response 404
-------------------------------android app----------------------------------------------
//app Send POST request.
if (doOutput && postData.length > 0) {
OutputStream outStream = connection.getOutputStream();
outStream.write(postData);
outStream.close();
}
//app Get response.
int responseCode = connection.getResponseCode();
if (responseCode != 200) {
events.onHttpError("Non-200 response to " + method + " to URL: " + url + " : "
+ connection.getHeaderField(null));
connection.disconnect();
return;
}
-----------------------------------android app---------------------------------------
The text was updated successfully, but these errors were encountered: