我在swift3.0项目中使用alamofire进行网络连接。我需要从woocommerce rest apis获取数据,例如http://woocommerce.github.io/woocommerce-rest-api-docs/#product-properties 下面是我在项目中添加的代码。我认为存在身份验证问题。
let params = ["oauth_consumer_key":consumerKey, "oauth_consumer_secret":consumerSecret, "oauth_timestamp":timeInterval, "oauth_nonce": nonce, "oauth_signature_method": "HMAC-SHA1", "oauth_version": "1.0"] as [String : Any];
Alamofire.request(url, parameters: params)
.responseJSON { response in
print(response.request) // original URL request
print(response.response) // HTTP URL response
print(response.data) // server data
print(response.result) // result of response serialization
if let JSON = response.result.value {
print("JSON: \(JSON)")
}
}
响应:
{
code = "woocommerce_rest_cannot_view";
data = {
status = 401;
};
message = "Sorry, you cannot view this resource.";
}