嗨,我有一个代码,检查字符串是否是回文.代码是这样的:
package ProjeTarahi;
import java.util.*;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.util.Scanner;
import java.util.logging.Level;
import java.util.logging.Logger;
import java.lang.String;
public class Main
{
public boolean CheckIsSymmetric(String s)
{
if (s.length()<=1)
{
return true;
}
if (s.charAt(0)==s.charAt(s.length()-1))
{
String sub = s.substring(1,s.length()-2);
return CheckIsSymmetric(sub);
}
else
{
return false;
}
}
public static void main(String args[])throws FileNotFoundException
{
Scanner sc=new Scanner(new FileInputStream(new File("in.txt")));
String input=sc.nextLine();
Main p=new Main();
if(p.CheckIsSymmetric(input)==true)
{
System.out.println("in reshte motegharen ast");
}
else
{
System.out.println("infinite");
}
}
} …Run Code Online (Sandbox Code Playgroud) 嗨,我正在尝试在Alamofire中创建自定义SessionManager,以更改默认的timeoutIntervalForRequest值。我正在使用以下代码:
let configuration=URLSessionConfiguration.default
configuration.timeoutIntervalForRequest=20
let sessionManager=Alamofire.SessionManager(configuration:configuration)
sessionManager.request("my url", method: .post, parameters: params, encoding: JSONEncoding.default, headers: header)
.responseJSON(completionHandler: { (response) in
if response.result.isSuccess{
//here goes the rest of my code
}
}
else{
//here goes the connection error part
}
})
Run Code Online (Sandbox Code Playgroud)
问题是我总是遇到错误部分,当我在错误部分打印响应时,它看起来像这样:
错误结束-代码:-999
失败:错误域= NSURLErrorDomain代码= -999“已取消”
就像我的请求立即取消一样。如果我将sessionManager更改为默认管理器Alamofire,它可以正常工作,但我需要更改timeoutIntervalForRequest值。我正在使用Xcode 9.3和Swift 4和Alamofire 4.7.2。有什么建议么?