【问题标题】:Get Request Status code: 400 Swift获取请求状态码:400 Swift
【发布时间】:2017-09-06 11:37:42
【问题描述】:

我收到代码错误**状态代码:400*

URL: https://conversation.8villages.com/1.0/contents/articles?state=published } 
{ status code: 400, headers {
Connection = "keep-alive";
"Content-Length" = 2;
"Content-Type" = "application/json";
Date = "Tue, 11 Apr 2017 07:49:13 GMT";
Server = nginx;

} }
2 bytes
SUCCESS
JSON: {

}

我的 json 结果成功但不显示我的数据?

实际上我得到了带有消费者密钥、消费者秘密、令牌密钥和令牌秘密的请求方法 Alamofire。像这样:

    let params: HTTPHeaders = ["oauth_consumer_key":"*****",
                               "oauth_consumer_secret":"*****",
                               "oauth_token_key":"*****.",
                               "oauth_token_secret": "*****",
                               "oauth_signature_method": "HMAC-SHA1",
                               "oauth_timestamp_key" : "1491366048",
                               "oauth_version": "1.0"] as [String : Any] as! HTTPHeaders;

    Alamofire.request("https://conversation.8villages.com/1.0/contents/articles?state=published", method: .get, headers: params).responseJSON { response in
        print("test", response.request!)  // original URL request
        print("ini responseny", response.response!) // HTTP URL response
        print("test", response.data!)     // server data
        print("test", response.result)   // result of response serialization

        if let JSON = response.result.value {
            print("JSON: \(JSON)")
        }
    }

如何获取我的数据 API ??

【问题讨论】:

  • 通常状态码 400 表示您的查询有问题。您的请求可能已成功,但服务器告诉您无法访问数据。
  • 从我的代码中,先生哪错了?
  • 不不,我不是说你的代码不正确。您发送的数据可能有问题。可能在您的标题或您的 url 参数中。
  • 也许您有关于 Alamofire 和 Oauth 先生的方法获取的参考文档?请
  • @MendaFernanda 在此处查看官方 Alamofire 文档github.com/Alamofire/Alamofire/tree/master/Documentation

标签: json swift oauth alamofire


【解决方案1】:

请记住:

400 Bad Request :服务器不能或不会处理请求 由于某些被认为是客户错误的事情(例如, 格式错误的请求语法、无效的请求消息帧,或 欺骗性请求路由)。

为了更好地理解检查:this

【讨论】:

  • 嘿Achraf!如何检测无效请求的原因是什么?
猜你喜欢
  • 2017-06-02
  • 1970-01-01
  • 1970-01-01
  • 2020-04-25
  • 1970-01-01
  • 2021-11-09
  • 2017-08-10
  • 2020-10-21
  • 1970-01-01
相关资源
最近更新 更多