我有 ASP.NET Web API操作,该操作由 iOS 设备上的特定应用程序调用。在浏览器中在智能手机或台式机上打开它时,它可以正常工作。但是,智能手机应用程序在使用IntegrityError at /add_blog/
NOT NULL constraint failed: blog_blog.author_id
调用时不会得到任何响应。如果我将iOS和服务器httpMethod = GET
更改为httpMethod
,则一切都按预期工作。
服务器代码:
POST
iOS代码:
[HttpGet("{uuid}")]
public async Task<ConfigurationProfileDto> Get([FromRoute]string uuid)
{
if (string.IsNullOrWhiteSpace(uuid))
return null;
var smartphone = _SmartphoneService.GetAll().FirstOrDefault(p => p.Uuid == uuid && p.StatusId == Data.Entities.SmartphoneStatusEnum.Active);
if (smartphone == null)
{
return null;
}
var profileDto = new ConfigurationProfileDto(smartphone.User.ConfigurationProfile);
return profileDto;
}
响应标题:
public func requestSend() {
delegate?.managerDidStartLoading?(request: self.requestObject)
requestInitialization()
sessionInitialization()
let task = session?.dataTask(with: request!, completionHandler: { data, response, error in
if error != nil {
self.delegate?.managerDidFailed(description: error!.localizedDescription, request: self.requestObject)
return
}
if let status = response as? HTTPURLResponse {
if status.statusCode == 200 {
self.delegate?.managerDidSuccessed(request: self.requestObject)
if let json = try? JSONSerialization.jsonObject(with: data!, options: []) {
self.delegate?.managerDidReceived?(data: json, request: self.requestObject!)
}
}
else {
self.delegate?.managerDidFailed(description: "Server returns code \(status.statusCode)", request: self.requestObject)
}
}
})
task?.resume()
}
private func requestInitialization() {
if let urlString = requestURL,
let url = URL(string: urlString) {
request = URLRequest(url: url)
request?.addValue("application/json", forHTTPHeaderField: "Content-Type")
request?.addValue("application/json", forHTTPHeaderField: "Accept")
request?.httpMethod = "GET"
request?.timeoutInterval = 120
do {
request?.httpBody = try JSONSerialization.data(withJSONObject: requestParameter!, options: .prettyPrinted)
}
catch let error {
delegate?.managerDidFailed(description: error.localizedDescription, request: self.requestObject)
}
}
else {
delegate?.managerDidFailed(description: "insufficent request parameters", request: self.requestObject)
}
}
为什么它不适用于transfer-encoding: chunked
content-type: application/json; charset=utf-8
server: Kestrel
date: Sun, 08 Apr 2018 05:23:44 GMT
?