我的代码下面有点工作,它创建User对象并保存,但它不保存密码:
class CreateUserResource(ModelResource):
class Meta:
allowed_methods = ['post']
object_class = User
authentication = Authentication()
authorization = Authorization()
include_resource_uri = False
fields = ['username']
def obj_create(self, bundle, request=None, **kwargs):
try:
bundle = super(CreateUserResource, self).obj_create(bundle, request, **kwargs)
except IntegrityError:
raise BadRequest('That username already exists')
return bundle
Run Code Online (Sandbox Code Playgroud)
如果我将"密码"添加到元字段,那么它会保存原始密码但不会对其进行散列.我究竟做错了什么?
所以这对我有用:
def obj_create(self, bundle, request=None, **kwargs):
username, password = bundle.data['username'], bundle.data['password']
try:
bundle.obj = User.objects.create_user(username, '', password)
except IntegrityError:
raise BadRequest('That username already exists')
return bundle
Run Code Online (Sandbox Code Playgroud) 如果在此处设置了身份验证凭据,如果提供的用户/密码正确,则一切正常,但如果它们不正确则会挂起.这不是服务器问题,我使用Curl和浏览器检查,不正确的凭据立即返回401:
Authenticator.setDefault(new Authenticator() {
protected PasswordAuthentication getPasswordAuthentication() {
return new PasswordAuthentication(user, password.toCharArray());
}
});
Run Code Online (Sandbox Code Playgroud)
挂起的代码在这里,它挂起在这一行:in = new BufferedReader(new InputStreamReader(httpURLConn.getInputStream())); (没有例外,它只停留在这条线上)
try {
URL url = new URL(resourceUrl);
HttpURLConnection httpURLConn = (HttpURLConnection) url.openConnection();
String rawData = "";
String currentLine = null;
BufferedReader in = null;
in = new BufferedReader(new InputStreamReader(httpURLConn.getInputStream()));
while ((currentLine = in.readLine()) != null) {
rawData = rawData.concat(currentLine);
}
in.close();
} catch (UnknownHostException e) {
Log.i(CLASS_NAME + "::" + METHOD_NAME
, "An exception occured while reading data from remote …
Run Code Online (Sandbox Code Playgroud) 我们正在使用HTTP基本身份验证向Web服务器发出基于HttpURLConnection的请求.代码在Android版本2.x,3.x.,4.0.x上运行良好现在使用Jelly Bean和v4.1.x身份验证失败,LogCat中包含以下消息:
01-27 10:54:18.886: ...::doReadRawData(731): An exception occured while reading data from remote host. httpURLConn.responseCode = 401 / httpURLConn.responseMessage = UNAUTHORIZED
01-27 10:54:18.886: ...::doReadRawData(731): java.io.IOException: No authentication challenges found
Run Code Online (Sandbox Code Playgroud)
我们在Android文档中使用HttpURLConnection的身份验证代码:
private void doAuthorize() {
Authenticator.setDefault(new Authenticator() {
protected PasswordAuthentication getPasswordAuthentication() {
return new PasswordAuthentication(USER, PASSWORD.toCharArray());
}
});
}
Run Code Online (Sandbox Code Playgroud)
经过进一步调查和排除故障后,我们发现4.1 Jelly Bean中没有调用此代码!
Android Jelly Bean 4.1中基本身份验证的解决方法或正确方法有哪些?
有人发现这个相关主题的Android源代码有所不同,我认为我们遇到的问题与这个差异有关:HttpURLConnection在Android 2.x中运行良好,但在4.1中没有运行:没有发现身份验证挑战
authentication android httpurlconnection basic-authentication android-4.2-jelly-bean
我正在尝试将a的图像属性设置为UIImageView
我正在模糊的图像CoreImage
.代码与未过滤的图像完美配合,但是当我将背景图像设置为过滤后的图像时,contentMode
似乎停止工作UIImageView
- 而不是填充方面,图像将垂直拉伸.除了设置contentMode
代码,我还在故事板上设置它,但结果是相同的.
我正在使用Swift 2/Xcode 7.
func updateBackgroundImage(image: UIImage) {
backgroundImage.contentMode = .ScaleAspectFill
backgroundImage.layer.masksToBounds = true
backgroundImage.image = blurImage(image)
}
func blurImage(image: UIImage) -> UIImage {
let imageToBlur = CIImage(image: image)!
let blurfilter = CIFilter(name: "CIGaussianBlur")!
blurfilter.setValue(10, forKey: kCIInputRadiusKey)
blurfilter.setValue(imageToBlur, forKey: "inputImage")
let resultImage = blurfilter.valueForKey("outputImage") as! CIImage
let croppedImage: CIImage = resultImage.imageByCroppingToRect(CGRectMake(0, 0, imageToBlur.extent.size.width, imageToBlur.extent.size.height))
let blurredImage = UIImage(CIImage: croppedImage)
return blurredImage
}
Run Code Online (Sandbox Code Playgroud)
为什么过滤CIImage
导致我的图像被忽略contentMode
,我该如何解决这个问题?
我正在尝试实现OpenSSL的OCSP功能,如此处所述,它需要X509对象作为参数.我所拥有的只是.cer格式的x.509证书文件.如何在OpenSSL中使用.cer证书初始化X509对象?(如果重要的话,我在XCode中使用OpenSSL 1.0.0g).