我想使用带有登录身份验证的curl在交换机点击监听器上发出OFF命令。 像http://admin:1234@10.1.1.83/outlet?4=OFF
一样我在这样的开关上设置了点击监听器,在点击监听器上我为curl调用了一个方法
switch4.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
getRequest();
}
});
现在,像这样的getRequest()方法......
public static String getRequest() {
StringBuffer stringBuffer = new StringBuffer("");
BufferedReader bufferedReader = null;
try {
HttpClient httpClient = new DefaultHttpClient();
HttpPost httpPost = new HttpPost();
URI uri = new URI("http://10.1.1.83/outlet?4=OFF");
httpPost.setURI(uri);
httpPost.addHeader(BasicScheme.authenticate(
new UsernamePasswordCredentials("admin", "1234"),
HTTP.UTF_8, false));
HttpResponse httpResponse = httpClient.execute(httpPost);
InputStream inputStream = httpResponse.getEntity().getContent();
bufferedReader = new BufferedReader(new InputStreamReader(
inputStream));
String readLine = bufferedReader.readLine();
while (readLine != null) {
stringBuffer.append(readLine);
stringBuffer.append("\n");
readLine = bufferedReader.readLine();
}
} catch (Exception e) {
// TODO: handle exception
} finally {
if (bufferedReader != null) {
try {
bufferedReader.close();
} catch (IOException e) {
// TODO: handle exception
}
}
}
return stringBuffer.toString();
}
答案 0 :(得分:2)
您可以使用 var _ = this, dataSettings, responsiveSettings, breakpoint;
方法使用用户名,密码凭据。
在这里,我向您展示方法。
[Violation] Added non-passive event listener to a scroll-blocking 'wheel' event. Consider marking event handler as 'passive' to make the page more responsive.
js?key=APIKEY:99
[Violation] Added non-passive event listener to a scroll-blocking 'mousewheel' event. Consider marking event handler as 'passive' to make the page more responsive.
util.js:40
[Violation] Added non-passive event listener to a scroll-blocking 'touchstart' event. Consider marking event handler as 'passive' to make the page more responsive.
util.js:40
[Violation] Added non-passive event listener to a scroll-blocking 'touchmove' event. Consider marking event handler as 'passive' to make the page more responsive.
在您的脚本中使用此代码,它将起作用。