获取用户信息异常'JWT strings must contain exactly 2 period characters. Found: 0'
时间: 2023-11-14 22:58:17 浏览: 238
根据引用,获取用户信息异常"'JWT strings must contain exactly 2 period characters. Found: 0'"是由于JWT字符串中缺少了两个句点字符导致的。JWT是一种用于在网络之间传递声明的开放标准(RFC 7519),它通常由三部分组成:头部(Header)、载荷(Payload)和签名(Signature),这些部分之间使用句点字符进行分隔。
根据引用的描述,可能是在登录接口的请求头(header)中没有传递正确的token参数,导致JWT字符串不完整,缺少了句点字符。请检查你的代码,确保在请求头中正确传递了token参数,并且该参数是一个有效的JWT字符串。
如果你需要进一步解决该异常,请检查以下几点:
1. 检查你的代码,确保在登录接口中生成的JWT字符串是正确的,并且包含了正确的头部、载荷和签名部分。
2. 检查你的代码,确保在请求头中传递了正确的token参数,并且该参数是一个有效的JWT字符串。
3. 检查你的代码,确保在拦截器中对JWT字符串进行了正确的解析和验证。
4. 检查你的代码,确保在拦截器中配置了正确的登录接口的放行规则。
希望以上建议能够帮助你解决该异常问题。如果你需要更多帮助,请提供更多代码或错误信息的细节。
相关问题
JWT strings must contain exactly 2 period characters. Found: 0
This error message indicates that the input provided as a JWT string does not have the expected format. JWT strings consist of three parts separated by period characters: the header, the payload, and the signature. Each of these parts should be base64-encoded and separated by a period character.
If the input provided does not contain any period characters, it is not a valid JWT string. It is possible that the input has been truncated or modified in some way, or that it was never intended to be a JWT string.
To resolve this error, ensure that the input provided is a valid JWT string with all three parts separated by exactly two period characters. If necessary, regenerate the JWT string or obtain a new one from the appropriate source.
jsonwebtoken.MalformedJwtException: JWT strings must contain exactly 2 period characters. Found: 0
这个错误是由于JWT字符串格式不正确导致的。JWT字符串由三部分组成,每个部分之间用点号分隔。这个错误提示表明JWT字符串中没有找到两个点号,因此它不符合JWT字符串的格式要求。可能的原因是在创建JWT字符串时,某些部分被省略或格式不正确。要解决这个问题,需要检查JWT字符串的格式是否正确,并确保它包含三个部分,每个部分之间用点号分隔。
以下是一个创建JWT字符串的示例代码,其中包含三个部分:头部,载荷和签名。请注意,每个部分都是一个JSON对象,并且它们之间用点号分隔。
```swift
import JWT
let header = Header(alg: .hs256)
let payload = Payload(iss: "fuller.li", iat: Date())
let signer = JWTSigner.hs256(key: "secret".data(using: .utf8)!)
let jwt = JWT(header: header, payload: payload)
let data = try jwt.sign(using: signer)
let jwtString = String(data: data, encoding: .utf8)
print(jwtString)
```
相关推荐
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)