Hello,
Sorry, I'm a B4A / HTTP amateur.
I'm trying to write a simple Android app to send a embedded command to a web server. ex http://address/relay?on=1. The server requires a username and password.
I have tried to use the B4A HTTP commands and are having no logon success. It appears my username and password are not being recognized by the server.
My B4A code successfully routes the HTTP request to the server and results in a successful response but the response shows the server did not recognize the user / password.
I've tried the
* http.executecredentials(URL, id, "user", "pass") and
* http.execute(URL, id)
Can anyone help?
Here is an example of how it's done in JAVA.... BTW this works....
// Establish an HTTP client for connections
HttpClient httpclient = new DefaultHttpClient();
// Define the GET request (Turn outlet 1 on)
HttpGet httpget = new HttpGet("http://192.168.0.100/outlet?1=ON");
// Add authentication to the GET request
String username = "user";
String password = "pass";
try {
UsernamePasswordCredentials credentials = new UsernamePasswordCredentials(username, password);
BasicScheme scheme = new BasicScheme();
Header authorizationHeader = scheme.authenticate(credentials, httpget);
httpget.addHeader(authorizationHeader);
} catch (AuthenticationException e) {
e.printStackTrace();
return;
}
try {
// Send the request to the WebPowerSwitch, store the response
HttpResponse response = httpclient.execute(httpget);
.....
Thanks!
Sorry, I'm a B4A / HTTP amateur.
I'm trying to write a simple Android app to send a embedded command to a web server. ex http://address/relay?on=1. The server requires a username and password.
I have tried to use the B4A HTTP commands and are having no logon success. It appears my username and password are not being recognized by the server.
My B4A code successfully routes the HTTP request to the server and results in a successful response but the response shows the server did not recognize the user / password.
I've tried the
* http.executecredentials(URL, id, "user", "pass") and
* http.execute(URL, id)
Can anyone help?
Here is an example of how it's done in JAVA.... BTW this works....
// Establish an HTTP client for connections
HttpClient httpclient = new DefaultHttpClient();
// Define the GET request (Turn outlet 1 on)
HttpGet httpget = new HttpGet("http://192.168.0.100/outlet?1=ON");
// Add authentication to the GET request
String username = "user";
String password = "pass";
try {
UsernamePasswordCredentials credentials = new UsernamePasswordCredentials(username, password);
BasicScheme scheme = new BasicScheme();
Header authorizationHeader = scheme.authenticate(credentials, httpget);
httpget.addHeader(authorizationHeader);
} catch (AuthenticationException e) {
e.printStackTrace();
return;
}
try {
// Send the request to the WebPowerSwitch, store the response
HttpResponse response = httpclient.execute(httpget);
.....
Thanks!
Last edited: