我试图使用JSch通过ssh连接到我的计算机,然后运行命令。
但是,当我运行代码时,我从未连接到计算机。和以下错误:
I/System.out: com.jcraft.jsch.JSchException: timeout: socket is not established
这是我的相关代码:
protected void sshTesting(){
String name = "";
String userName = "kalenpw";
String password = "hunter2";
String ip = "192.168.0.4";
int port = 22;
String command = "cmus-remote -u";
try{
JSch jsch = new JSch();
Session session = jsch.getSession(userName, ip, port);
session.setPassword(password);
session.setConfig("StrictHostKeyChecking", "no");
System.out.println("Establishing connection");
session.connect(10);
Channel channel = session.openChannel("exec");
((ChannelExec)channel).setCommand(command);
channel.setInputStream(null);
channel.connect(10000);
// name = session.getUserName();
// System.out.println(session.getHost());
}
catch(Exception e){
System.err.print(e);
System.out.print(e);
}
}
Run Code Online (Sandbox Code Playgroud)
这是我第一次使用JSch,所以我几乎只关注他们的一个示例Exec.java …
当我尝试 POST 到给定的 url 时,当前收到一条错误消息。GET 在同一个域上工作正常,这是我的错误:
CORS 策略阻止了在 ' http://localhost:8000/api/users/login '处访问 XMLHttpRequest来自源 ' http://localhost:8080 ' 已被 CORS 策略阻止:对预检请求的响应未通过访问控制检查:否请求的资源上存在“Access-Control-Allow-Origin”标头。
我发现无数问题记录了同样的问题,所有这些问题都包含修改我的 Cors 中间件的变体。
目前我的 CORS 中间件如下所示:
class Cors
{
public function handle($request, Closure $next)
{
if ($request->isMethod('OPTIONS')) {
$response = Response::make();
} else {
$response = $next($request);
}
return $response
->header('Access-Control-Allow-Origin', '*')
->header('Access-Control-Allow-Methods', 'GET, POST, PUT, DELETE, OPTIONS')
->header('Access-Control-Allow-Headers', 'Content-Type, Accept, Authorization, X-Requested-With, Application');
}
}
Run Code Online (Sandbox Code Playgroud)
错误指出 No 'Access-Control-Allow-Origin' 我相信我->header('Access-Control-Allow-Origin', '*')应该处理它,因为 * 是我理解的通配符。我错过了这里有什么不同的问题吗?Stack 是 Laravel 后端,VueJS 前端使用 Axios 进行 HTTP …
我试图使WPF文本块上的每行文本以不同的颜色显示.我有以下代码,使整个块的字体颜色为紫色,因为这是它设置的最后一种颜色.我怎样才能使每种药水以不同的颜色显示?
private void btnShowPotions_Click(object sender, RoutedEventArgs e) {
tbPotionInfo.Foreground = Brushes.Green;
tbPotionInfo.Text = smallPotion.Name + "(" + smallPotion.AffectValue + ")\r\n";
tbPotionInfo.Foreground = Brushes.Blue;
tbPotionInfo.Text += mediumPotion.Name + "(" + mediumPotion.AffectValue + ")\r\n";
tbPotionInfo.Foreground = Brushes.Red;
tbPotionInfo.Text += largePotion.Name + "(" + largePotion.AffectValue + ")\r\n";
tbPotionInfo.Foreground = Brushes.Purple;
tbPotionInfo.Text += extremePotion.Name + "(" + extremePotion.AffectValue + ")\r\n";
}
Run Code Online (Sandbox Code Playgroud) 我的应用程序中存在一个问题,我需要根据按下一根手指还是两根手指来执行不同的操作。
目前我有以下代码:
@Override
public boolean onTouchEvent(MotionEvent event){
int touchX = (int)event.getX();
int touchY = (int)event.getY();
int action = event.getActionMasked();
//Multitouch
if(event.getPointerCount() > 1 && action == MotionEvent.ACTION_POINTER_DOWN){
System.out.println("2 Finger press");
return true;
}
else if(action == MotionEvent.ACTION_DOWN && action != MotionEvent.ACTION_POINTER_DOWN){
if(event.getPointerCount() == 1) {
System.out.println("single finger down");
invalidate();
return true;
}
}
return false;
}
Run Code Online (Sandbox Code Playgroud)
我遇到的问题是,当我用 2 个手指按下时,多点触控部分会注册,之后单次按下也会注册。
我在谷歌上搜索了一些解决这个问题的方法,这就是为什么我要检查action != MotionEvent.ACTION_POINTER_DOWN我认为可以解决问题的单点触摸条件。这并没有解决问题,因此我决定检查一下event.getPointerCount() == 1,但不幸的是,当我用两根手指按下时,仍然会导致打印两行。
总而言之,当按下 2 个手指而不是同时按下两个手指时,我只需要调用 2 个手指部分。