Skip to content
This repository has been archived by the owner on Apr 27, 2021. It is now read-only.

i have httpurlconnection problem #56

Open
jgshin1109 opened this issue Aug 10, 2018 · 0 comments
Open

i have httpurlconnection problem #56

jgshin1109 opened this issue Aug 10, 2018 · 0 comments

Comments

@jgshin1109
Copy link

jgshin1109 commented Aug 10, 2018

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---------------------------------------

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant